Hide The Getter Or Add In The Proto Object
Solution 1:
You can embed an anonymous prototype
using Object.create()
, though do note that this slightly deterioratesdrastically 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 codeHow...
buttonsData[name] = Object.assign(Object.create({
getsprite() { returnthis.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
:
classButtonsData{
constructor (data = {}) {
Object.assign(this, data)
}
get sprite () { returnthis.slot.currentSprite }
}
And use it like this:
buttonsData[name] = new ButtonsData({ name, type: bType, slot })
Solution 2:
Those __defineGetter__
, __defineSetter__
, __lookupGetter__
and __lookupSetter__
properties you see there have nothing to do with your sprite
getter. They are just native (but long deprecated) methods of Object.prototype
(which is the object that you have expanded in your view). There's nothing you can do against them.
Post a Comment for "Hide The Getter Or Add In The Proto Object"