Created
October 22, 2016 16:43
-
-
Save nodew/058db89e1a79365663bc99aec43d2e55 to your computer and use it in GitHub Desktop.
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
function store() {} | |
function closure(obj) { | |
store.print = function() { | |
console.log(obj) | |
} | |
return function() { | |
store.print() | |
} | |
} | |
var c1 = closure({a: 1, b: 2}) | |
c1() | |
var c2 = closure({a: 3, b: 4}) | |
c2() | |
c1() | |
/** | |
* the outout is | |
* { a: 1, b: 2 } | |
* { a: 3, b: 4 } | |
* { a: 3, b: 4 } | |
*/ |
ltchronus
commented
Oct 24, 2016
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment