Page 91 - Nodejs 교과서 개정2판
P. 91
§ Ӓܿ FYQPSUT৬ NPEVMF FYQPSUT ҙ҅
8BSOJOH FYQPSUT ё ࢎਊ द
exports ёܳ ࢎਊೡ ٸח module.exports৬ ଵઑ ҙ҅о ӵ ঋب۾ ೧ঠ פ module.exportsীח যڃ
чٚ ੑ೧ب غ݅ exportsীח ߈٘द ёۢ ࣘࢿݺҗ ࣘࢿчਸ ੑ೧ঠ פ exportsী ܲ чਸ ੑೞݶ
ё ଵઑ ҙ҅о Րѹ ؊ ࢚ ݽٕ۽ ӝמೞ ঋणפ
exportsܳ ࢎਊೡ ٸח ё݅ ࢎਊೡ ࣻ ਵ۽ GVOD KT৬ э module.exportsী ೣࣻܳ ੑೠ ҃ীח exports۽
߄Ե ࣻ হणפ
exports৬ module.exportsীח ଵઑ ҙ҅о ਵ۽ ೠ ݽٕী exports ё৬ module.exportsܳ زदী ࢎਊೞ ঋ
ח Ѫ જणפ
/PUF ֢٘ীࢲ UIJTח ޖੌөਃ
֢٘ীࢲ thisܳ ࢎਊೡ ٸ ೧ঠ ೡ णפ
this.js
console.log(this);
console.log(this === module.exports);
console.log(this === exports)
function whatIsThis() {
console.log('function', this === exports, this === global);
}
whatIsThis();
콘솔
$ node this
{}
true
true
function false true
ܲ ࠗ࠙ ࠳ۄ ߄झ݀৬ زੌೞ݅ ୭࢚ਤ झী ઓೞח thisח module.exports ژח exports ё
ܳ оܻఈפ ژೠ ೣࣻ ࢶޙ ղࠗ thisח global ёܳ оܻఈפ
ߣীח ݽٕਸ ࠛ۞য়ח requireী ೧ ঌইࠇद requireח ೣࣻҊ ೣࣻח ё۽ requireח ё
۽ࢲ ݻ о ࣘࢿਸ ыҊ णפ Ӓীࢲ require.cache৬ require.mainী ೧ ঌইࠁѷणפ
WBS KTо ח Ҕী SFRVJSF KTܳ ٟ݅פ