Last active
January 9, 2018 06:05
-
-
Save ChillyBwoy/1f682e9c1902269c6b77e311ff823492 to your computer and use it in GitHub Desktop.
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
function factory() { | |
var count = 0; | |
return function() { | |
function fx() { | |
count += 1; | |
return fx; | |
} | |
fx.valueOf = function() { | |
return count; | |
}; | |
return fx(); | |
} | |
} | |
var f1 = factory(); | |
console.log(f1()()); // 2 | |
console.log(f1()()); // 4 | |
console.log(f1()()); // 6 | |
var f2 = factory(); | |
console.log(f2()); // 1 | |
console.log(f2()()); // 3 | |
console.log(f2()()()); // 6 | |
var f3 = factory(); | |
console.log(f3()()()); // 3 | |
console.log(f3()()()); // 6 | |
console.log(f3()()()); // 9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment