Skip to content

Instantly share code, notes, and snippets.

@akagr
Created February 20, 2014 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akagr/9112682 to your computer and use it in GitHub Desktop.
Save akagr/9112682 to your computer and use it in GitHub Desktop.
Borrowed from john resig's tutorial. A very nice example to test one's grasp on closures.
var a = 5;
function runMe(a){
assert( a == ___, "Check the value of a." );
function innerRun(){
assert( b == ___, "Check the value of b." );
assert( c == ___, "Check the value of c." );
}
var b = 7;
innerRun();
var c = 8;
}
runMe(6);
for ( var d = 0; d < 3; d++ ) {
setTimeout(function(){
assert( d == ___, "Check the value of d." );
}, 100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment