Created
June 22, 2016 05:00
-
-
Save maxehnert/05f0d746bdb69426266833d682123706 to your computer and use it in GitHub Desktop.
es5 vs es6 cyclic dependencies
This file contains 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
const subtractModule = require('./subtract.js'); | |
exports.countAdd = 0; | |
exports.add = function(n = 0) { | |
exports.countAdd++; | |
console.log('countAdd', exports.countAdd); | |
subtractModule.countSubtract++ | |
console.log('countSubtract from add file', subtractModule.countSubtract); | |
if (n < 20) return subtractModule.subtractfn(n + 1); | |
} | |
subtractModule.subtractfn(exports.countAdd); |
This file contains 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
const addModule = require('./add.js'); | |
exports.countSubtract = 0; | |
exports.subtractfn = function(n = 0) { | |
exports.countSubtract++; | |
console.log('countSubtract', exports.countSubtract); | |
if (n < 20) return addModule.add(n + 1); | |
} |
This file contains 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
import { subtractfn, countSubtract } from './subtract'; | |
export var countAdd = 0; | |
export function add(n = 0) { | |
countAdd++; | |
console.log('countAdd', countAdd); | |
countSubtract++; | |
console.log('countSubtract from add file', countSubtract); | |
if (n < 20) return subtractfn(n + 1); | |
} | |
subtractfn(countAdd); |
This file contains 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
import { countAddPre, add } from './add'; | |
export var countSubtract = 0; | |
export function subtractfn(n = 0) { | |
countSubtract++; | |
console.log('countSubtract', countSubtract); | |
if (n < 20) return add(n + 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment