define(function(require, exports, module){
`require` 是一个方法,接受 [模块标识] 作为唯一参数,用来获取其他模块提供的接口。
// eg:
// 获取模块 a 的接口
// var a = require('./a');
// 调用模块 a 的方法
// a.doSomething();
exports 是一个对象,用来向外提供模块接口。
正确的写法是用 return 或者给 module.exports 赋值:以下两种写法是正确的
// 正确写法
module.exports = {
foo: 'bar',
doSomething: function() {}
};
// 通过 return 直接提供接口
return {
foo: 'bar',
doSomething: function() {}
};
})
module 是一个对象,上面存储了与当前模块相关联的一些属性和方法。
module.exports 表示当前模块对外提供的接口。对应上面的exports的写法
网友评论