for..in, hasOwnProperty(), and inheritance
Axel Rauschmayer
axel at rauschma.de
Tue Nov 8 11:17:18 PST 2011
>> What’s the use case?
>
> I thought I gave a pretty reasonable one before, but just in case:
Thanks! Shorter is better... ;-)
> 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, so the more straightforward solution is to make a copy and modify there or to non-destructively merge:
https://developer.yahoo.com/yui/3/examples/yui/yui-merge.html
--
Dr. Axel Rauschmayer
axel at rauschma.de
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
More information about the es-discuss
mailing list