Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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!"
Add Comment
Please, Sign In to add comment