简体   繁体   English

如何在带有JavaScript的node.js中使用一个源文件?

[英]How can I use one source file in node.js with javascript?

I have one code in node.js. 我在node.js中有一个代码。

var testFunc = function( y, m, d ) {
        //- do something~~
        return chkDObj.getFullYear( ) == y && chkDObj.getMonth( ) == m && chkDObj.getDate( ) == d;
};

res.render( "index.jade", { testFunc: testFunc } );

In jade, 在玉中

script 
    var tmp = #{testFunc}

I want it to show same thing, but render result is, 我希望它显示相同的东西,但是渲染结果是,

<script>
var tmp = function( u, m, d ) {
        //- do something~~
        return chkDObj.getFullYear( ) == y &amp;&amp; chkDObj.getMonth( ) == m &amp;&amp; chkDObj.getDate( ) == d;
        };
</script>

How can I manage one source file? 如何管理一个源文件?

You can create js file like a utils.js, which is accessible through http and such as Node.js module. 您可以创建utils.js之类的js文件,该文件可通过http访问,例如Node.js模块。 It's simple and works. 这很简单而且有效。

Jade escapes all data by default. Jade默认情况下会转义所有数据。 You can disable escaping by changing jour jade template: 您可以通过更改Jour Jade模板来禁用转义:

script 
    var tmp = !{testFunc}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM