Skip to content

Instantly share code, notes, and snippets.

@EmmanuelKasper

EmmanuelKasper/closure.js

Last active Dec 16, 2016
Embed
What would you like to do?
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