【发布时间】:2015-09-24 08:58:24
【问题描述】:
我有以下车把助手,在打字稿文件中定义。
当为帮助程序提供字符串"test" 和10 的maxResidualLength 时,调试器语句被命中,尽管检查器告诉我clippedString.length > maxResidualLength 等于false
Handlebars.registerHelper("ClipYearsFromString", function (strg: string, maxResidualLength:number) {
var pattern = /(\b\d{4}.\b|\b\d{4}\b)/g; //remove sets of four digits or four digits with a non alpha character behind them.
var clippedString = strg.replace(pattern, "");
if (typeof (maxResidualLength) == "number" && maxResidualLength > 0)
{
if (clippedString.length > maxResidualLength);
{
debugger;
clippedString = clippedString.substr(0, maxResidualLength) + "…";
}
}
return clippedString;
});
帮助器在模板中被调用如下:
<span>{{{ClipYearsFromString SelectedRankingPool.PoolName 10}}}</span>
SelectedRankingPool.PoolName 始终是一个字符串。
这是怎么回事? 所有主流浏览器都会出现相同的行为,无论是 Chrome、Firefox 还是 IE ,如果我在打字稿和车把之外进行辅助注册,它仍然会发生。
function derp(strg, maxResidualLength)
{
var pattern = /(\b\d{4}.\b|\b\d{4}\b)/g;
var clippedString = strg.replace(pattern, "");
if (typeof (maxResidualLength) == "number" && maxResidualLength > 0)
{
if (clippedString.length > maxResidualLength);
{
debugger;
clippedString = clippedString.substr(0, maxResidualLength) + "…";
}
}
return clippedString;
}
console.log(derp("test", 10)); //hits debugger
【问题讨论】:
标签: javascript typescript handlebars.js