-
-
Save getify/a9afbf1d23a5c51efe158888b88ba63e to your computer and use it in GitHub Desktop.
example of closure?
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 A() { | |
var x = 1; | |
C(B); | |
function B() { console.log(x); } | |
function C(callback) { | |
B === callback; // true | |
B(); // is this console.log() using a closure or not? depends on perspective. | |
callback(); // ditto | |
} | |
} | |
A(); | |
// 1 | |
// 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment