Mustache.render()和Mustache.to_html()之间有什么区别?

eha*_*abd 22 javascript mustache

文件没有提及Mustache.to_html()的,但每一个教程为Mustache.js在线使用Mustache.to_html().所以我肯定错过了一些珠宝.

代码示例将非常感谢.

McG*_*gle 31

看看源代码,似乎to_html基本上已被弃用:

// This is here for backwards compatibility with 0.4.x.
exports.to_html = function (template, view, partials, send) {
    var result = render(template, view, partials);

    if (typeof send === "function") {
      send(result);
    } else {
      return result;
    }
};
Run Code Online (Sandbox Code Playgroud)

如你所见,它调用渲染.一个区别是额外(可选)发送参数,它是它调用的回调(将结果作为参数发送).

  • 非常感谢你.对我来说很好的教训是开始查看源代码. (4认同)