module.exports require, script, , , exports, , module.exports . module.exports, , , , , ?
, exports - , , , script tada.js:
exports = function(){
console.log('Tada');
}
console.log(exports);
console.log(module.exports);
script app.js:
var tada = require('./tada');
?
, :
console.log(exports);
console.log(module.exports);
exports module.exports . , , , , , ? , , , JavaScript .
JavaScript, = , , , , , reference exports module.exports , exports module.exports , :
exports = function(){
console.log('Tada');
}
, exports .
also remember that to return a function module.exports, the return function is not exportsrequired, so we got an empty object for module.exportsin our example, and after the link is broken module.exports, they exportsno longer point to the same object.
To fix this, you need mutateto overwrite instead. so if we change our example to this, both exportsand module.exportswill have the same value:
exports.tada = function(){
console.log('Tada');
}
console.log(exports);
console.log(module.exports);