Last active
March 12, 2017 03:09
-
-
Save CoralSilver/2d96aafa8309e49d262832a3002d4158 to your computer and use it in GitHub Desktop.
Increment function using 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 makeIncrementer(x) { | |
return function() { | |
return x++; | |
}; | |
} | |
var increment = makeIncrementer(0); | |
console.log(increment()); //0 | |
console.log(increment()); //1 | |
console.log(increment()); //2 | |
console.log(increment()); //3 | |
console.log(increment()); //4 | |
console.log(increment()); //5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment