exports用法

//写法1
exports.hello = function(){
    console.log(‘world’);
}

//写法2
var f = {
    hello : function(){
        console.log(‘world’);
    }
}
module.exports = f;

假设我们写的这个模块的文件名为hello.js,执行下面的代码
var h = require(‘hello’);
h.hello();

对于上面的两种写法,执行这段代码后得出的结果是一样的。

猜你喜欢

转载自www.cnblogs.com/juanjuanxiliu/p/9071778.html
今日推荐