node 的exports 和module

文件05
/**
* Created by Mr.tiankong on 2017/3/24.
*/
var People = require("./test/people.js");

var xiaoming = new People("小明","男","12");

xiaoming.sayHello();

文件People
/**
* Created by Mr.tiankong on 2017/3/25.
*/
function People(name,sex,age)
{
this.name = name;
this.sex = sex;
this.age = age;
}
People.prototype =
{
sayHello:function()
{
console.log("这是模块儿里的"+this.name + this.sex + this.age);
}
}
//不能用 exports.People = Peole 了 这是 规矩 有语法
//应该用 module 来暴露 功能是一样的 只是 方法不同
module.exports = People;
文件foo
/**
* Created by Mr.tiankong on 2017/3/25.
*/
var msg="你好";
var info = "呵呵";
function showInfo(){
console.log("闭包");
}

//必须暴露这个对象 可以暴露无数变量
exports.msg = msg;
exports.info = info;
exports.

posted on 2017-03-25 13:01  童彪  阅读(235)  评论(0编辑  收藏  举报

导航