Skip to content

Instantly share code, notes, and snippets.

@sevperez
Created July 18, 2018 18:18
Show Gist options
  • Save sevperez/51dfed55441d05987e376908d8965f78 to your computer and use it in GitHub Desktop.
Save sevperez/51dfed55441d05987e376908d8965f78 to your computer and use it in GitHub Desktop.
// prototypes4.js
var House = {
ringDoorbell: function() {
console.log("ding dong!");
},
describe: function() {
console.log(this.owner + "'s house has " + this.rooms + " rooms.");
}
};
var Castle = Object.create(House);
Castle.describe = function() {
console.log(this.owner + " owns a mighty castle with " + this.rooms + " rooms!");
};
var hearstCastle = Object.create(Castle);
hearstCastle.owner = "William Randolph Hearst";
hearstCastle.rooms = 56;
hearstCastle.describe();
// Logs: "William Randolph Hearst owns a mighty castle with 56 rooms!"
hearstCastle.ringDoorbell();
// Logs: "ding dong!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment