Last active
December 17, 2015 11:39
-
-
Save cognitom/5604098 to your computer and use it in GitHub Desktop.
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
| var MyNamespace = {}; | |
| MyNamespace.Person = function(){ | |
| /* Public Fields */ | |
| this.name = ''; | |
| this.sex = 'M'; | |
| /* Private Fields */ | |
| var _age = 0; | |
| /* Constructor */ | |
| this.initialize = function(name, sex, age){ | |
| this.name = name; | |
| this.sex = sex; | |
| _age = age; | |
| return this; | |
| }; | |
| /* Methods */ | |
| this.getAge = function(){ | |
| return _age; | |
| }; | |
| }; | |
| MyNamespace.Woman = function(){ | |
| var parent = new MyNamespace.Person(); | |
| parent.constructor.apply(this); | |
| /* Public Fields */ | |
| this.sex = 'F'; | |
| /* Constructor */ | |
| this.initialize = function(name, age){ | |
| parent.initialize.call(this, name, this.sex, age); | |
| return this; | |
| }; | |
| }; | |
| var she = (new MyNamespace.Woman()).initialize('Hanako', 25); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment