Skip to content

Instantly share code, notes, and snippets.

@kenbod
Created February 11, 2015 15:28
Show Gist options
  • Save kenbod/5ad7e6d50595074b89c5 to your computer and use it in GitHub Desktop.
Save kenbod/5ad7e6d50595074b89c5 to your computer and use it in GitHub Desktop.
IIFE Example
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