Created
July 24, 2013 09:17
-
-
Save jineeshjohn/6069139 to your computer and use it in GitHub Desktop.
Information Hiding and closures
This file contains hidden or 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
//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