Created
February 22, 2011 04:41
-
-
Save jgautier/838239 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
var addNumber=function(x){ | |
//first class function : a function treated as an object | |
return function(y){ | |
//x is a free variable. (i.e. not a local variable or an argument of this function.) | |
//x is bound to the argument x in lexical environment defined by the addNumber function | |
return x+y; | |
}; | |
}; |
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
var foo="bar"; | |
$("#aButton").click(function(){//passing a function in as an object (i.e. first class function) | |
alert(foo);//foo is bound in the global lexical environment | |
}); |
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
var myModule=(function(){ | |
var x=1; | |
return getX(){//return a function as an object (i.e. first class function) | |
return x;//x is bound to the lexical environment defined by the outer function | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment