for own(...) loop (spin-off from Re: for..in, hasOwnProperty(), and inheritance)
raynos2 at gmail.com
Tue Nov 8 17:59:25 PST 2011
On Tue, Nov 8, 2011 at 11: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 personally use `Object.keys()` on all my objects just because it's a
neater construct. I havn't really run into much problems with the `this`
value. None more then I would be forgetting it on any other inner function.
As an aside `break and continue` are emulated using `Object.keys(o).any`.
But that is rarely done. Trying to access outer arguments or returning from
inside the loop is also rare. the former is gaurded by unpacking arguments
at the top of the function and the latter is gaurded by using `.any` again
and propagating the return value. (Most of the time if I return from a loop
it's a boolean)
However on average a lot more people will use for ... in with
hasOwnProperty because ES5 environments are rare and a lot of people avoid
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss