Okay that makes sense, but the `Object.forIn` confused me, then that'd be a bad name because then its not really looping like for-in
On Fri, Mar 4, 2016 at 4:07 PM Logan Smyth <[email protected]> wrote: > Edwin, the original example loop explicitly checks `obj.hasOwnProperty(key)`, > so properties in the prototype chain are not an issue here. > > On Fri, Mar 4, 2016 at 1:04 PM, Edwin Reynoso <[email protected]> wrote: > >> Sorry guys but this is very wrong, for in, loops through all properties >> even the ones inherited from all prototypes, while Object.keys() and >> Object.entries() do not. They are indeed very different >> >> On Fri, Mar 4, 2016 at 1:45 PM Langdon <[email protected]> wrote: >> >>> Ahhh, nothing. I never think about destructuring. Thanks! >>> >>> On Fri, Mar 4, 2016 at 1:41 PM, Caitlin Potter <[email protected]> >>> wrote: >>> >>>> > Object.entries does look nice, but 2 arguments is more >>>> straightforward than a passing around a pair. >>>> >>>> What’s the problem with `for (let [key, value] of Object.entries(obj)) >>>> { …. }` >>>> >>>> > As well (and perhaps more importantly), temporarily building an array >>>> of arrays so we can forEach it, seems way less efficient than forIn >>>> is/would be. >>>> >>>> You might be surprised — If the pair never reaches geriatric status >>>> (old generation/tenured space, etc), it could be allocated and cleaned up >>>> relatively quickly. >>>> >>>> On Mar 4, 2016, at 1:28 PM, Langdon <[email protected]> wrote: >>>> >>>> My gripe with Object.keys is that it requires a closure to use >>>> effectively. >>>> >>>> Object.entries does look nice, but 2 arguments is more straightforward >>>> than a passing around a pair. >>>> >>>> As well (and perhaps more importantly), temporarily building an array >>>> of arrays so we can forEach it, seems way less efficient than forIn >>>> is/would be. >>>> >>>> On Fri, Mar 4, 2016 at 1:20 PM, Isiah Meadows <[email protected]> >>>> wrote: >>>> >>>>> Yeah, and those effectively nullify this, anyways. >>>>> >>>>> On Fri, Mar 4, 2016, 12:55 Simon Blackwell < >>>>> [email protected]> wrote: >>>>> >>>>>> Not sure of the rationale; however, it looks like Chrome now supports >>>>>> something similar natively: >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> https://twitter.com/malyw/status/704972953029623808?utm_source=javascriptweekly&utm_medium=email >>>>>> >>>>>> >>>>>> >>>>>> *From:* es-discuss [mailto:[email protected]] *On >>>>>> Behalf Of *Langdon >>>>>> *Sent:* Friday, March 4, 2016 11:22 AM >>>>>> *To:* [email protected] >>>>>> *Subject:* Object.prototype.forIn >>>>>> >>>>>> >>>>>> >>>>>> My apologies if this has been discussed before (I have to imagine it >>>>>> has, but couldn't find anything). >>>>>> >>>>>> >>>>>> >>>>>> Why isn't there a `forIn` method on Object natively? >>>>>> >>>>>> >>>>>> >>>>>> Something that simply wraps this all-to-common code: >>>>>> >>>>>> >>>>>> >>>>>> var key; >>>>>> >>>>>> >>>>>> >>>>>> for (key in obj) { >>>>>> >>>>>> if (obj.hasOwnProperty(key) === true) { >>>>>> >>>>>> ... >>>>>> >>>>>> } >>>>>> >>>>>> } >>>>>> >>>>>> >>>>>> >>>>>> Example: https://jsfiddle.net/langdonx/d4Lph13u/ >>>>>> >>>>>> >>>>>> >>>>>> TIA, >>>>>> >>>>>> Langdon >>>>>> _______________________________________________ >>>>>> es-discuss mailing list >>>>>> [email protected] >>>>>> https://mail.mozilla.org/listinfo/es-discuss >>>>>> >>>>> >>>> _______________________________________________ >>>> es-discuss mailing list >>>> [email protected] >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> >>>> >>>> >>> _______________________________________________ >>> es-discuss mailing list >>> [email protected] >>> https://mail.mozilla.org/listinfo/es-discuss >>> >> -- >> Thanks >> - Edwin >> >> _______________________________________________ >> es-discuss mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> >> > -- Thanks - Edwin
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

