suppose this is my code snippet
let myHeroes = [“thor”, “spiderman”];
let heroPower = {
thor: “hammer”,
spiderman: “sling”,
getSpiderPower: function () {
console.log(spider power is ${this.spiderman}
);
}
};
heroPower.getSpiderPower();
heroPower.proto.getThorPower = function () {
return thor power is ${heroPower.thor}
;
};
heroPower.getThorPower();
Now since regular objects in javascript don’t have access to the prototype in order to add this functionality to the object heropower do I really need to write proto after the object name to add properties or is there another easy way ?
I tried using heroPower.prototype.getThorPower=function(){..}
but it resulted in an error
I expect to add get thorpower function within the heroPower object without explicitly defining that function inside the object inserting it from outside the object