Skip to content

Instantly share code, notes, and snippets.

@kennethzfeng
Created August 13, 2014 03:11
Show Gist options
  • Select an option

  • Save kennethzfeng/c9d65c3b736c787414b5 to your computer and use it in GitHub Desktop.

Select an option

Save kennethzfeng/c9d65c3b736c787414b5 to your computer and use it in GitHub Desktop.
Dynamically Create Javascript Classes
function AccountFactory(name) {
function AccountClass(accountNumber) {
this.accountNumber = accountNumber;
}
AccountClass.getClassName = function() {
return name + 'Account';
};
return AccountClass;
}
var CheckingAccount = AccountFactory('Checking');
var account = new CheckingAccount('123232');
console.log(CheckingAccount.getClassName());
console.log(account.accountNumber);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment