1. Create a JS file (funs.js)
Function Controller (req,res) {
Res.write ("send");
Call (' Hello ', req,res);
Res.end ("");
}
Module.exports = controller; Only one of the functions in this file is published
Other files are called:
Require ('./models/funs.js ');
Controller (request,response); Call directly
In 2.funs.js
---can Declare multiple functions
module.exports={
Getvisit:function () {
Return visitnum++;
},
Add:function (a, B) {
Return a+b;
}
}
Call:
var funs = require ('./models/funs.js ');
Funs.getvisit ();
Funs.add (6,3);
3. Dynamic function calls
See: 650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" background:url ("/E/U261/LANG/ZH-CN /images/localimage.png ") no-repeat center;border:1px solid #ddd;" alt= "spacer.gif"/>http://study.163.com/course/ Introduction/1003228034.htm#/coursedetail
In the 3rd section
This article is from the "nanshan mining chrysanthemum" blog, Please be sure to keep this source http://hezudao.blog.51cto.com/6872139/1869143
Two ways to encapsulate functions in Node. JS