Created
August 13, 2014 03:11
-
-
Save kennethzfeng/c9d65c3b736c787414b5 to your computer and use it in GitHub Desktop.
Dynamically Create Javascript Classes
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
| 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