Skip to content

Instantly share code, notes, and snippets.

@jineeshjohn
Created July 24, 2013 09:17
Show Gist options
  • Save jineeshjohn/6069139 to your computer and use it in GitHub Desktop.
Save jineeshjohn/6069139 to your computer and use it in GitHub Desktop.
Information Hiding and closures
//Information hiding
function User(){
var username = "Jineesh";
this.getName = function(){
return username;
}
}
var u = new User();
u.getName();
//Closure usage
function getHandler(n) {
return function() {
alert( 'You clicked on: ' + n );
};
}
for (var i = 0; i < 100; ++i) {
myElements[i].onclick = getHandler(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment