I have this sample constructor that creates new Loot objects:
function Loot(type, sellValue) {
this.type = type;
this.sellValue = sellValue;
}
I want to extend these properties to other objects and add them to an array like so:
var inventory = [];
var stone = new Loot("craft", 20);
inventory.push(stone);
var hat = new Loot("clothing", 80);
inventory.push(hat);
var coal = new Loot("ore", 5);
inventory.push(coal);
var diamond = new Loot("ore", 400);
inventory.push(diamond);
console.log(inventory);
But the problem is that when I check my inventory, it shows (Loot, Loot, Loot, Loot)
instead of the actual names of the items (stone, hat, coal, diamond)
.
How can I fix this issue? Do I need to implement some kind of inheritance?
Thanks!