Javascript 我可以在mustache.js模板中调用全局函数吗? 函数fun(){ log(“乐趣被称为”); 返回“有趣的结果”; } 测试:{{window.fun()}}

Javascript 我可以在mustache.js模板中调用全局函数吗? 函数fun(){ log(“乐趣被称为”); 返回“有趣的结果”; } 测试:{{window.fun()}},javascript,templates,mustache,Javascript,Templates,Mustache,在本例中,从未调用fun()。是否可以调用全局函数?Handlebar.js是解决方案。似乎Handlebar就是答案。“我们编写Handlebar.js而不仅仅是使用mustache.js的主要动机之一是允许用户定义全局助手。” <script> function fun() { console.log("fun was called"); return "fun result"; } <

在本例中,从未调用fun()。是否可以调用全局函数?

Handlebar.js是解决方案。

似乎Handlebar就是答案。“我们编写Handlebar.js而不仅仅是使用mustache.js的主要动机之一是允许用户定义全局助手。”
    <script>
        function fun() {
          console.log("fun was called");
          return "fun result";
        }
    </script>

    <script id="template" type="text/template">            
         test: {{window.fun()}}            
    </script>