我正在寻找一种方法来覆盖" if"在把手中帮助做预处理,但随后调用原来的帮助器来完成其余的繁重工作。
如果我这样做,它会设置一个无限循环:
// objectCreate is just a function that's supposed to clone an object.
Handlebars._helpers = objectCreate(Handlebars.helpers);
Handlebars.registerHelper('if', function(conditional, options){
console.log("if helper");
conditional = false;
Handlebars._helpers["if"].call(this, conditional, options)
});
以前有人必须这样做吗?我知道我可以制作一个像#34; conIf"然后调用原件,但如果可能的话我想保留相同的名称。
感谢您的帮助!
答案 0 :(得分:0)
终于明白了:
Handlebars._helpers = {};
// This is what somehow breaks the pointer and stops it from forever looping.
for(var i in Handlebars.helpers){
Handlebars._helpers[i] = Handlebars.helpers[i];
}
Handlebars.registerHelper('if', function(conditional, options){
return Handlebars._helpers["if"].call(Handlebars, conditional, options);
});