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

Andrew Paprocki andrew at ishiboo.com
Tue Nov 8 17:26:29 PST 2011


On Tue, Nov 8, 2011 at 6:36 PM, Brendan Eich <brendan at mozilla.com> wrote:
> Ignoring performance, a lot of stylish JS hackers use Object.keys(o).forEach. How many run into the wrong |this| (arguments/break/continue/return)? Not clear. Something to study.

I was curious so I did some grok-ing across my code sample and
Object.keys() is barely used. The usage of the |for in| construct is 2
orders of magnitude larger than the usage of hasOwnProperty(),
supporting the thought that no one really does it the "right" way.

The MDN page for Object.keys does not talk about |this| being wrong in
certain situations. If you could elaborate on that, it would be
helpful to know.

-Andrew


More information about the es-discuss mailing list