Skip to content

Instantly share code, notes, and snippets.

@EmmanuelKasper
Last active December 16, 2016 11:43
Show Gist options
  • Save EmmanuelKasper/5a0dd0fabe63462f627319d105a04327 to your computer and use it in GitHub Desktop.
Save EmmanuelKasper/5a0dd0fabe63462f627319d105a04327 to your computer and use it in GitHub Desktop.
Closure Example
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