Last active
December 16, 2016 11:43
-
-
Save EmmanuelKasper/5a0dd0fabe63462f627319d105a04327 to your computer and use it in GitHub Desktop.
Closure Example
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 loneTalker = {}; | |
var addSpeach = function(name) { | |
var text = 'Hello ' + name; | |
var talk = function() { | |
console.log(text); | |
}; | |
loneTalker.talk = talk; | |
}; | |
addSpeach('manu'); | |
loneTalker.talk(); //expect 'Hello manu' as talk has still access to 'text' reference | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment