Skip to content

Instantly share code, notes, and snippets.

@zmts
Last active June 19, 2016 18:59
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 zmts/664f781f16b1485ce9a58cc872b8b42a to your computer and use it in GitHub Desktop.
Save zmts/664f781f16b1485ce9a58cc872b8b42a to your computer and use it in GitHub Desktop.
// 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