Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. function SuperHuman (name, superPower) {
  2. this.name = name;
  3. this.superPower = superPower;
  4. }
  5.  
  6. SuperHuman.prototype.usePower = function () {
  7. console.log(this.superPower + "!");
  8. };
  9.  
  10. var banshee = new SuperHuman("Silver Banshee", "sonic wail");
  11.  
  12. // Outputs: "sonic wail!"
  13. banshee.usePower();
  14.  
  15. /* *********************************************** */
  16. function SuperHero (name, superPower) {
  17. this.name = name;
  18. this.superPower = superPower;
  19. this.allegiance = "Good";
  20. }
  21.  
  22. SuperHero.prototype.saveTheDay = function () {
  23. console.log(this.name + " saved the day!");
  24. };
  25.  
  26. var marvel = new SuperHero("Captain Marvel", "magic");
  27.  
  28. // Outputs: "Captain Marvel saved the day!"
  29. marvel.saveTheDay();
  30.  
  31. function SuperHero (name, superPower) {
  32. // Reuse SuperHuman initialization
  33. SuperHuman.call(this, name, superPower);
  34.  
  35. this.allegiance = "Good";
  36. }
  37.  
  38. /* *********************************************** */
  39.  
  40. SuperHero.prototype = new SuperHuman();
  41.  
  42. SuperHero.prototype.saveTheDay = function () {
  43. console.log(this.name + " saved the day!");
  44. };
  45.  
  46. var marvel = new SuperHero("Captain Marvel", "magic");
  47.  
  48. // Outputs: "Captain Marvel saved the day!"
  49. marvel.saveTheDay();
  50.  
  51. // Outputs: "magic!"
  52. marvel.usePower();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement