반응형
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fileA.js | |
let a = 3; | |
let b = 4; | |
exports.sum = function(c, d) { | |
console.log( "[fileA] sum() : a = " + a ); | |
console.log( "[fileA] sum() : b = " + b ); | |
console.log( "[fileA] sum() : c = " + c ); | |
console.log( "[fileA] sum() : d = " + d ); | |
return a + b + c + d; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fileB.js | |
let a = 5; | |
let b = 6; | |
let moduleA = require("./fileA.js"); | |
let retA = moduleA.sum(a,b); // 3+4+5+6 = 18 | |
console.log( "[fileB] retA = " + retA ); | |
let e = 5; | |
f = 6; | |
console.log( "[fileB] (before require) e = " + e + ", f = " + f); | |
let moduleC = require("./fileC.js"); | |
console.log( "[fileB] (after require) e = " + e + ", f = " + f); | |
let retC = moduleC.sum(e,f); // 3+4+5+4 = 14 | |
console.log( "[fileB] retC = " + retC ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// fileC.js | |
let e = 3; | |
f = 4; | |
exports.sum = function(g, h) { | |
console.log( "[fileC] sum() : e = " + e ); | |
console.log( "[fileC] sum() : f = " + f ); | |
console.log( "[fileC] sum() : g = " + g ); | |
console.log( "[fileC] sum() : h = " + h ); | |
return e + f + g + h; | |
} |
728x90
반응형
'Javascript' 카테고리의 다른 글
non TDZ (0) | 2018.11.22 |
---|---|
closure (0) | 2018.11.22 |
fibonacci.js (0) | 2018.11.08 |
iteration from 'Learning Javascript' (0) | 2018.11.08 |
화살표 함수 Arrow function of javascript (0) | 2018.09.28 |