Created
July 18, 2018 18:18
-
-
Save sevperez/51dfed55441d05987e376908d8965f78 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
// 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