web-dev-qa-db-ja.com

Mustache.render()とMustache.to_html()の違いは何ですか?

documentation はMustache.to_html()について言及していませんが、Mustache.jsオンラインのすべての tutorial はMustache.to_html()を使用しています。したがって、私は確かにいくつかの宝石を逃しています。

コード例をいただければ幸いです。

22
ehabd

source を見ると、 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;
    }
};

ご覧のとおり、renderを呼び出します。 1つの違いは、追加の(オプションの)sendパラメーターです。これは、呼び出すコールバックです(パラメーターとして結果を送信します)。

31
McGarnagle