Created
July 18, 2018 18:17
-
-
Save sevperez/00a1ac1bc34abf91418ae0009b8c5f46 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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