|
|
|
|
|
by iamleppert
5590 days ago
|
|
This is a prime example of pre-mature optimization. This, but itself, although interesting theoretically provides no practical information and should not dictate most application use or non-use of getters and setters. Unless you're doing many millions of get/set operations a second, you will not see any benefit and time is more likely better spent in other areas (selectors, caching, DOM element reduction, etc). That said, I am very interested why the prototype getter/setter is also bad. I wasn't expecting this to be quite as awful. I would imagine the javascript engine could cache or dynamically create an organic function from a prototype style reference (so there would be huge performance gains over many iterations). |
|
My guess as to why the prototype getters/setters are slow is that the prototype list has to be traversed and this requires a bunch of lookups that are not necessary when dealing with direct properties of the object.