Javascript inheritance
function Animal(name) {
this.name = name;
this.breathe = function() {
// do something
}
}
function Dog(name) {
Animal.call(this, name);
this.bark = function() {
// do something
}
}
Dog.prototype = new Animal();
Dog.prototype.constructor = Dog;
var dog = new Dog("Rex");
console.log(dog instanceof Dog);
console.log(dog instanceof Animal);
console.log(Dog.prototype.constructor);
console.log(Dog.name);
Written by Hercules Merscher
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#