Le 08/11/2011 21:49, Brendan Eich a écrit :
The recommended practice when writing for-in loops in JS today is to write:

  for (i in o) {
    if (o.hasOwnProperty(i)) {
/body/
    }
  }
As said in the thread your forked from, this practice is often recommended to not enumerate Object.prototype methods (rather than enumerating only own properties)

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.
Why would developers use for own while they currently do not use hasOwnProperty? I really am skeptical on this. Enumeration of own enumerable properties can be done with Object.keys. Why not encourage people to use this? Are you also proposing an addition of for own (... of ...) if for-own-in and for-of are both accepted?

David
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to