Created
May 20, 2016 12:56
-
-
Save razorcd/51bdcc8f1bbefb21eeeaaded5f6be86c to your computer and use it in GitHub Desktop.
JavaScript 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
//simple | |
var var1 = 1; | |
var func1 = function(input) { | |
//var var2 = 2; | |
return input + var1; // + var2; | |
} | |
console.log(func1(1)); | |
console.dir(func1); | |
console.log("-------------"); | |
//detailed | |
var var10= 1; | |
var func10 = function(input) { | |
var func11 = function(){ | |
return input + 10; | |
} | |
return func11; | |
} | |
console.log(func10(1)()); | |
console.dir(func10(1)); | |
console.log("-------------"); | |
var customFunc10For5 = new func10(5) | |
console.log(customFunc10For5()); | |
console.dir(customFunc10For5); | |
console.log("______________"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment