Skip to content

Instantly share code, notes, and snippets.

@EnoF
Created February 11, 2014 18:37
Show Gist options
  • Save EnoF/8941149 to your computer and use it in GitHub Desktop.
Save EnoF/8941149 to your computer and use it in GitHub Desktop.
Super and Constructor!
var Animal = clazz(function Animal(){
this.private = {
name: 'animal'
};
this.public = {
sayHello: function sayHello(){
return 'Hi, my name is ' + this.private.name + '!';
}
};
this.constructor = function constructor(name){
this.private.name = name;
};
});
var Dog = clazz(function Dog(){
this.extend = 'Animal';
this.public = {
sayHello: function sayHello(){
return this.super.sayHello() + ' How are you?';
}
};
this.constructor = function constructor(name){
this.super.constructor(name);
};
});
var dog = new Dog('Brian');
dog instanceof Animal; //True
dog.sayHello(); //Hello, my name is Brian! How are you?
dog.name; //undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment