Created
May 30, 2016 21:22
-
-
Save explicite/34f243e4358fb1ba9016264bae4c52f5 to your computer and use it in GitHub Desktop.
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
/* | |
OOP modeling | |
*/ | |
//class | |
function Man(firstName, secondName, age, sex) { | |
//public | |
this.firstName = firstName; | |
this.secondName = secondName; | |
this.age = age || 0; | |
this.sex = sex; | |
}; | |
//static final | |
Man.SexEnum = { | |
MALE : 'male', | |
FEMALE : 'female' | |
}; | |
Object.freeze(Man.SexEnum); | |
Man.prototype = { | |
fullName : function () { | |
return this.firstName + ' ' + this.secondName; | |
} | |
} | |
var male = new Man('first', 'second', 10, Man.SexEnum.MALE); | |
//Female extends Man | |
function Female(firstName, secondName, age) { | |
Man.call(this, firstName, secondName, age, Man.SexEnum.FEMALE); | |
}; | |
var female = new Female('first', 'second', 18); | |
console.log(female); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment