For-has-in loop
You could use Object.keys, Object.entries, or Object.values on the right
side of of
instead.
And I find it kind of absurd that engines don't yet optimize away the
intermediate array allocation (even though it's literally almost equal
to for ... in
in performance).
Isiah Meadows me at isiahmeadows.com
Looking for web consulting? Or a new website? Send me an email and we can get started. www.isiahmeadows.com
On Mon, Feb 19, 2018 at 1:50 PM, Sebastian Malton <sebastian at malton.name>
wrote:
I would like to propose that the following be valid since it is a very common use case.
for (const field has in object) { .... }
Would be equivalent to:
for (const field in object) { if (!object.hasOwnPropety(field)) { continue; } .... }
I'm generally supportive of getting rid of error-prone calls to hasOwnProperty methods since they fail when there is a "hasOwnProperty" field anywhere on the prototype chain between object and Object.prototype.
This idiom looks like something that usually almost means what its author intends but rarely exactly.
Are there any proposals for an in
operator variant that only checks for
own properties?
If so, the syntax could be synchronized with that.
(I thought there was one but couldn't find it on
tc39/proposals )
An HTML attachment was scrubbed... URL: esdiscuss/attachments/20180219/20addd75/attachment