for..in, hasOwnProperty(), and inheritance

Felipe Gasper felipe at felipegasper.com
Tue Nov 8 11:48:53 PST 2011


On 11/8/11 1:17 PM, Axel Rauschmayer wrote:
>>> What’s the use case?
>>
>> In YUI, it’s impossible to use this otherwise-useful pattern:
>> ---------
>> var base_config = { width: "600px" };
>>>> var my_config = Object.create(base_config);
>> my_config.visible = false;
>> var widget = new Y.Widget(my_config);
>> ---------
>> In the example above, YUI will not see the “width” property because
>> YUI rejects all inherited properties when it iterates through the
>> configuration hash.
>
>
> Got it, you want to non-destructively modify base_config. It is kind
> of tricky to know when to stop traversing the prototype chain, …

Actually, have you ever seen a use case of wanting to prevent iteration 
through inherited properties *other* than Object.prototype? (Besides 
using for..in on Array objects.)

All of the examples I’ve ever seen of the problems that ensue from 
for..in iteration and prototypes stem from extending Object.prototype. 
Why not, then, specifically address that problem rather than preventing 
all iteration through inherited properties?

-FG


More information about the es-discuss mailing list