Handlebars助手是否有可能从另一个Handlebars助手继承?例如:
Handlebars.registerHelper('DateHelper', function(date, format) {
if (!date) return;
var formatted = format;
return new Handlebars.SafeString('<time>' + formatted + '</time>');
});
Handlebars.registerHelper('shortDate', function(date) {
// I want to something like this..
return Handlebars.helper.DateHelper(date, moment(value).format('D MMM YYYY'));
});
答案 0 :(得分:0)
据我所知,不能直接从一个Handlebars助手继承到另一个Handlebars助手,但是可以使用普通的构造函数,例如:
var DateHelper = function HandlebarsDateHelper(date, format) {
return new Handlebars.SafeString('<time>' + format + '</time>');
};
Handlebars.registerHelper('shortDate', function(date) {
if (!date) return;
return new HandlebarsDateHelper(date, moment(value).format('D MMM YYYY'));
});