Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function SuperHuman (name, superPower) {
- this.name = name;
- this.superPower = superPower;
- }
- SuperHuman.prototype.usePower = function () {
- console.log(this.superPower + "!");
- };
- var banshee = new SuperHuman("Silver Banshee", "sonic wail");
- // Outputs: "sonic wail!"
- banshee.usePower();
- /* *********************************************** */
- function SuperHero (name, superPower) {
- this.name = name;
- this.superPower = superPower;
- this.allegiance = "Good";
- }
- SuperHero.prototype.saveTheDay = function () {
- console.log(this.name + " saved the day!");
- };
- var marvel = new SuperHero("Captain Marvel", "magic");
- // Outputs: "Captain Marvel saved the day!"
- marvel.saveTheDay();
- function SuperHero (name, superPower) {
- // Reuse SuperHuman initialization
- SuperHuman.call(this, name, superPower);
- this.allegiance = "Good";
- }
- /* *********************************************** */
- SuperHero.prototype = new SuperHuman();
- SuperHero.prototype.saveTheDay = function () {
- console.log(this.name + " saved the day!");
- };
- var marvel = new SuperHero("Captain Marvel", "magic");
- // Outputs: "Captain Marvel saved the day!"
- marvel.saveTheDay();
- // Outputs: "magic!"
- marvel.usePower();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement