Skip to content

Instantly share code, notes, and snippets.

@explicite
Created May 30, 2016 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save explicite/34f243e4358fb1ba9016264bae4c52f5 to your computer and use it in GitHub Desktop.
Save explicite/34f243e4358fb1ba9016264bae4c52f5 to your computer and use it in GitHub Desktop.
/*
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