To incorporate an unidentified prototype
, you can utilize Object.create()
. However, it's essential to acknowledge that this practice mildly degrades significantly enhances performance without a valid reason other than "it bothers my eyes in a debug terminal."
I do not endorse implementing this method in code that requires high performance How...
buttonsData[name] = Object.assign(Object.create({
get sprite() { return this.slot.currentSprite }
}), {
name: name,
type: bType,
slot: slot
});
This results in an object structured like this:
{
name: "Spines",
slot: Slot,
type: "sheetsType",
__proto__: {
get sprite: function () {...},
__proto__: Object
}
}
For improved reusability, it might be preferable to create a class
instead of generating an anonymous prototype
for each object appended to buttonsData
:
class ButtonsData {
constructor (data = {}) {
Object.assign(this, data)
}
get sprite () { return this.slot.currentSprite }
}
Implement it as follows:
buttonsData[name] = new ButtonsData({ name, type: bType, slot })