Created
February 11, 2015 15:28
-
-
Save kenbod/5ad7e6d50595074b89c5 to your computer and use it in GitHub Desktop.
IIFE 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 account = (function(account_name) { | |
var number_of_logins = 0; | |
var profile_name = ""; | |
var login = account_name; | |
return { | |
login : function() { return login; }, | |
name : function() { return profile_name; }, | |
setName : function(name) { profile_name = name; }, | |
increment: function() { number_of_logins++; }, | |
count : function() { return number_of_logins; } | |
} | |
} ("admin")); | |
account.setName("Ken Anderson"); | |
console.log("account.login: %s", account.login()); | |
console.log("account.name : %s", account.name()); | |
console.log("account.count: %d", account.count()); | |
console.log("Login twice..."); | |
account.increment(); | |
account.increment(); | |
console.log("account.count: %d", account.count()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment