Learning nodejs-03

Source: Internet
Author: User

Using modules

First application:

Module/apputils.jsexports.random = function () {    return math.random ();} Exports.showauthor = function () {    return "Chenlong";} App.jsvar ut = require ('./module/apputils '); Console.info (' ...... Start app ... '); var rn = Ut.random (); var my = Ut.showauthor (); Console.info (RN); Console.info (my); Console.info (' ... end app ... ');

The second type of application:

Module/user.jsvar User = function () {    var id;    var name;    var age;} User.prototype.show = function () {    console.info (this.id + ': ' + this.name + ': ' + this.age);} module.exports = user;  var u1 = new User ();//module.exports.user = user; var u1 = new User.user ();   App.jsvar user = require ('./module/user '); Console.info (' ..... Start app ... '); var u1 = new User (); u1.id=1; U1.name= ' Chenlong '; u1.age = 23;u1.show (); Console.info (' ..... end app ... ');


This article from the "Sky Sea-wide" blog, declined to reprint!

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.