学习nodejs -03
2020-12-13 03:47
标签:function require return start 使用模块 第一种应用: 第二种应用: 本文出自 “天空海阔” 博客,谢绝转载! 学习nodejs -03,搜素材,soscw.com 学习nodejs -03 标签:function require return start 原文地址:http://ether007.blog.51cto.com/8912105/1411298//module/AppUtils.js
exports.random = function () {
return Math.random();
}
exports.showAuthor = function () {
return "chenlong";
}
//app.js
var 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.......‘);
//module/User.js
var 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.js
var 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.......‘);