Last active
June 19, 2016 18:59
-
-
Save zmts/664f781f16b1485ce9a58cc872b8b42a 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
// parent class | |
function Animal(name) { | |
this.name = name; | |
}; | |
Animal.prototype.getName = function() { | |
return console.log(this.name); | |
}; | |
// child class | |
function Dog(name){ | |
this.name = name; | |
}; | |
Dog.prototype.bark = function() { | |
return console.log('Dog ' + this.name + ' is barking'); | |
}; | |
// Dog class inherit Animal class | |
// Dog.prototype = Object.create(Animal.prototype); | |
Dog.prototype.__proto__ = Animal.prototype; | |
// init | |
var dog = new Dog ('Goofy'); | |
dog.getName(); // 'Goofy' | |
dog.bark(); // 'Dog Goofy is barking' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment