On Apr 11, 2011, at 8:58 PM, David Bruant wrote:
> Le 11/04/2011 21:47, Brendan Eich a écrit :
>> On Apr 11, 2011, at 6:36 PM, Allen Wirfs-Brock wrote:
>>
>>> Personally, I prefer Object.getOwnPropertyDescriptor as a property
>>> existence test because it doesn't have the reflection the meta-circularity
>>> concern. I would write Dave's original function as:
>>>
>>> function getDefiningObject(obj, key) {
>>> var obj={}.valueOf.call(obj); // ToObject in case primitive value passed
>>> while (obj) {
>>> if (Object.getOwnPropertyDescriptor(obj,key)) return obj;
>>> obj = Object.getPrototypeOf(obj);
>>> }
>>> throw new Error("key " + key + " not found");
>>> }
>> Then the only downside is the pd allocation. Any way to avoid that?
> Could static analysis help out to detect that the object is not going to
> be used and consequently avoid the allocation?
Of course, but that's a bit much and unless it is adopted by all the "bigs",
web developers won't count on it and may shy away from the allocation (based on
real measurements or premature optimization, doesn't matter).
It's not the end of the world to have a pd allocation, of course. But an API
that avoids it without analysis might be worth considering.
/be
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss