for own (i in o) { //body } I'd rather see something like
for (i inside o) { //body } And the reason for this is you could then use it in conditions as you use in: if ( 'prop' in obj ) { //body } if ( 'prop' inside obj ) { //body } You would have 'prop' inside obj <=> Object.prototype.hasOwnProperty.call( obj, 'prop' ) On Wed, Nov 9, 2011 at 12:41 PM, David Bruant <bruan...@gmail.com> wrote: > Le 09/11/2011 02:26, Andrew Paprocki a écrit : >> >> On Tue, Nov 8, 2011 at 6:36 PM, Brendan Eich<bren...@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. > > The |this| differs between the body of a for-in and the argument callback in > the .forEach. Nothing to do with Object.keys. .forEach has a second optional > argument which is the value to be used as |this| so that you don't have to > do a .bind. > > David > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss