Guest User

Untitled

a guest
Jul 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. // prototypes4.js
  2.  
  3. var House = {
  4. ringDoorbell: function() {
  5. console.log("ding dong!");
  6. },
  7.  
  8. describe: function() {
  9. console.log(this.owner + "'s house has " + this.rooms + " rooms.");
  10. }
  11. };
  12.  
  13. var Castle = Object.create(House);
  14. Castle.describe = function() {
  15. console.log(this.owner + " owns a mighty castle with " + this.rooms + " rooms!");
  16. };
  17.  
  18. var hearstCastle = Object.create(Castle);
  19. hearstCastle.owner = "William Randolph Hearst";
  20. hearstCastle.rooms = 56;
  21.  
  22. hearstCastle.describe();
  23. // Logs: "William Randolph Hearst owns a mighty castle with 56 rooms!"
  24.  
  25. hearstCastle.ringDoorbell();
  26. // Logs: "ding dong!"
Add Comment
Please, Sign In to add comment