Skip to content

Instantly share code, notes, and snippets.

@cognitom
Last active December 17, 2015 11:39
Show Gist options
  • Select an option

  • Save cognitom/5604098 to your computer and use it in GitHub Desktop.

Select an option

Save cognitom/5604098 to your computer and use it in GitHub Desktop.
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