Skip to content

Instantly share code, notes, and snippets.

@sevperez
Created July 18, 2018 18:17
Show Gist options
  • Save sevperez/00a1ac1bc34abf91418ae0009b8c5f46 to your computer and use it in GitHub Desktop.
Save sevperez/00a1ac1bc34abf91418ae0009b8c5f46 to your computer and use it in GitHub Desktop.
// prototypes2.js
var House = {
ringDoorbell: function() {
console.log("ding dong!");
},
describe: function() {
console.log(this.owner + "'s house has " + this.rooms + " rooms.");
}
};
var bobsHouse = Object.create(House);
console.log(Object.getPrototypeOf(bobsHouse));
// Logs: {ringDoorbell: ƒ, describe: ƒ}
console.log(Object.getPrototypeOf(bobsHouse) === House);
// Logs: true
bobsHouse.describe();
// Logs: "undefined's house has undefined rooms."
bobsHouse.owner = "Bob Belcher";
bobsHouse.rooms = 4;
bobsHouse.describe();
// Logs: "Bob Belcher's house has 4 rooms."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment