for..in, hasOwnProperty(), and inheritance

Jake Verbaten raynos2 at gmail.com
Tue Nov 8 11:41:25 PST 2011


You shouldnt store properties on the prototype chain like that. Your
abusing Object.create as a shallow copy. Use a real shallow copy method.

On Nov 8, 2011 7:07 PM, "Felipe Gasper" <felipe at felipegasper.com> wrote:

On 11/8/11 12:37 PM, Axel Rauschmayer wrote: > > What’s the use case?
I thought I gave a pretty reasonable one before, but just in 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_co...

>
> > Don’t forget that whenever you set a property, you only ever modify the
> > first object in the prot...
>

Right…that’s why gave() walks the prototype chain unless it finds the
property *on* the object itself.

> > The “own property” debate mainly exists, because objects are (ab)used
as > dictionaries. Then ...
I disagree. That’s actually the crux of what I’m getting at.

IMO, you actually do want “inherited entries”; what you don’t want are
specifically those things inherited from Object.prototype. Weeding out
*all* inherited properties assumes that there is no legitimate use case for
objects inheriting from other objects…which defeats the whole purpose of
stuff like Object.create().

-FG

_______________________________________________ es-discuss mailing list
es-discuss at mozilla.org http...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111108/b55314da/attachment.html>


More information about the es-discuss mailing list