You can embed an anonymous prototype
using Object.create()
, though do note that this slightly deteriorates drastically improves performance for no reason other than "it disturbs my eyes in a debug terminal".
I do not advocate the use of this approach in performance-critical code How...
buttonsData[name] = Object.assign(Object.create({
get sprite() { return this.slot.currentSprite }
}), {
name: name,
type: bType,
slot: slot
});
This creates an object like this:
{
name: "Spines",
slot: Slot,
type: "sheetsType",
__proto__: {
get sprite: function () {...},
__proto__: Object
}
}
For re-usability, it would probably be better to implement a class
instead of creating an anonymous prototype
for each object added to buttonsData
:
class ButtonsData {
constructor (data = {}) {
Object.assign(this, data)
}
get sprite () { return this.slot.currentSprite }
}
And use it like this:
buttonsData[name] = new ButtonsData({ name, type: bType, slot })