Skip to content

Instantly share code, notes, and snippets.

@hakunin
Created December 13, 2009 11:16
Show Gist options
  • Select an option

  • Save hakunin/255386 to your computer and use it in GitHub Desktop.

Select an option

Save hakunin/255386 to your computer and use it in GitHub Desktop.
1. scope variable accesibility
...
var color = 'green';
var fun = function() { alert(color) }
..
fun() // alert('green')
// variables that are accesible
// in the scope in which a function
// is defined are accesible within
// that function once called
2. trick to bind variable into the function
var fun = function(color) {
return function() { alert(color) }
}('green')
fun() // alert('green')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment