The solution is pretty straightforward.
Handlebars will output the properties of the object you're passing into the templates, if the property is a function, it will execute the function and output the returned value
In your example the function doesn't return any value (it just calls alert), so the output is empty.
You could create an helper method like this:
handlebars.registerHelper('stringifyFunc', function(fn) {
return new Handlebars.SafeString("(" +
fn.toString().replace(/"/g,"'") + ")()");
});
Then from within the template you just need to use it on the function that needs to be stringified:
<div id="divTemplate">
<span onclick="{{stringifyFunc func}}">{{text}}</span>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…