for own(...) loop (spin-off from Re: for..in, hasOwnProperty(), and inheritance)

Timmy Willison timmywillisn at gmail.com
Tue Nov 8 13:45:09 PST 2011


Yes, I think JS needs something like this.  This is new to no one here, but
my main concern with using hasOwnProperty is the loss of performance, so I
think it would be worth exploring more than just syntactic sugar.  But I
don't know how realistic it is to hope for that.

http://jsperf.com/hasownproperty-vs-for-in/4#c300

On Tue, Nov 8, 2011 at 3:49 PM, Brendan Eich <brendan at mozilla.com> wrote:

> The recommended practice when writing for-in loops in JS today is to write:
>
>   for (i in o) {
>     if (o.hasOwnProperty(i)) {
>       *body*
>     }
>   }
>
> Although many JS developers do not follow the recommendation (out of
> ignorance or intentionally, doesn't matter).
>
> Should ES.next provide sugar for the recommended pattern? To make it
> compose with declarations and destructuring in the for head, it should use
> a contextual keyword immediately after 'for':
>
>   for own (i in o) {
>     *body*
>   }
>
> This is a small thing but it might pay off in the long run.
>
> /be
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111108/ca8684d8/attachment.html>


More information about the es-discuss mailing list