Skip to content

Instantly share code, notes, and snippets.

@abm0
Last active October 12, 2019 20:01
Show Gist options
  • Save abm0/7ba8be7a8d557c9e58a3c0f063c40ace to your computer and use it in GitHub Desktop.
Save abm0/7ba8be7a8d557c9e58a3c0f063c40ace to your computer and use it in GitHub Desktop.
function Plant(name) {
this.name = name;
};
Plant.prototype.height = 0;
Plant.prototype.grow = function() {
this.height += 1;
};
let plant = new Plant('hibiscus');
plant.grow();
console.log(plant); // { name: 'hibiscus', height: 1 }
function Tree() {
Plant.apply(this, arguments);
this.type = 'tree';
};
Tree.prototype = Plant.prototype;
let tree = new Tree('pine');
console.log(tree); // { name: 'pine', type: 'tree' }
console.log(tree.height); // 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment