Two ways to encapsulate functions in Node. JS

Source: Internet
Author: User



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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.