Providing object iterators beyond just Object.keys()
http://lmgtfy.com/?q=site%3Aesdiscuss.org+object.values From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Gijs Kruitbosch Sent: Tuesday, May 26, 2015 10:33 To: es-discuss at mozilla.org Subject: Providing object iterators beyond just Object.keys() Hello, When writing JS loops over objects, given the environment I'm in, I find myself using the gecko/spidermonkey-only "Iterator()" construct a lot for loops or array comprehensions: for (let [key, val] of Iterator(plainJSObject)) { // do stuff with both key and val } It seems the plan is to remove "Iterator()" (cf. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator ). Are there plans to add things like Object.values() (to produce Object.keys(obj).map(k => obj[k]) ) or Object.iterator (Object.keys(obj).map(k => [k, obj[k]])) so as to enable such usecases to be written easily in ES7 or later? Obviously I can create my own iterator, but it starts to get tedious if I need to do this in every file where I need to iterate over an object's own (enumerable) properties... (using Maps here is difficult because writing hardcoded nested structures of Maps is not nearly as neat as doing the same with Objects) Gijs -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150526/58e56932/attachment.html>
Perhaps surprisingly, I had actually asked around and looked through recent threads. Apologies for not having found the previous discussions from a year ago. It seems that after the call for a strawman in the meeting notes from April 2014, there was silence? esdiscuss.org/topic/object-entries-in-2015 asks the same. I don't really know whether it's more useful to continue replying here or pull up that thread (is one month "old" by es-discuss standards?). Either way, it would be useful to know what the current status is, which none of the posts/notes that I saw really clarify.
Perhaps surprisingly, I had actually asked around and looked through recent threads. Apologies for not having found the previous discussions from a year ago. It seems that after the call for a strawman in the meeting notes from April 2014, there was silence? https://esdiscuss.org/topic/object-entries-in-2015 asks the same. I don't really know whether it's more useful to continue replying here or pull up that thread (is one month "old" by es-discuss standards?). Either way, it would be useful to know what the current status is, which none of the posts/notes that I saw really clarify. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150526/1ceb4164/attachment-0001.html>
Silence because it wasn't a priority, relative to finishing ES6. It's not forgotten and still on track for ES7 development.
Silence because it wasn't a priority, relative to finishing ES6. It's not forgotten and still on track for ES7 development. Rick On Tue, May 26, 2015 at 11:59 AM Gijs Kruitbosch <gijskruitbosch at gmail.com> wrote: > Perhaps surprisingly, I had actually asked around and looked through > recent threads. Apologies for not having found the previous discussions > from a year ago. It seems that after the call for a strawman in the meeting > notes from April 2014, there was silence? > https://esdiscuss.org/topic/object-entries-in-2015 asks the same. I don't > really know whether it's more useful to continue replying here or pull up > that thread (is one month "old" by es-discuss standards?). Either way, it > would be useful to know what the current status is, which none of the > posts/notes that I saw really clarify. > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150526/5ebb4dc0/attachment.html>
Has anyone drafted a proposal for this? Is anyone assigned as champion yet?
Has anyone drafted a proposal for this? Is anyone assigned as champion yet? On Tue, May 26, 2015 at 11:05 AM, Rick Waldron <waldron.rick at gmail.com> wrote: > Silence because it wasn't a priority, relative to finishing ES6. It's not > forgotten and still on track for ES7 development. > > Rick > On Tue, May 26, 2015 at 11:59 AM Gijs Kruitbosch <gijskruitbosch at gmail.com> > wrote: > >> Perhaps surprisingly, I had actually asked around and looked through >> recent threads. Apologies for not having found the previous discussions >> from a year ago. It seems that after the call for a strawman in the meeting >> notes from April 2014, there was silence? >> https://esdiscuss.org/topic/object-entries-in-2015 asks the same. I >> don't really know whether it's more useful to continue replying here or >> pull up that thread (is one month "old" by es-discuss standards?). Either >> way, it would be useful to know what the current status is, which none of >> the posts/notes that I saw really clarify. >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss > > -- Shape Security is hiring outstanding individuals. Check us out at *https://shapesecurity.com/jobs/ <https://shapesecurity.com/jobs/>* -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150526/19884869/attachment.html>
No draft written, but I am the current champion. If you'd like to get something started, we can co-champion :)
No draft written, but I am the current champion. If you'd like to get something started, we can co-champion :) Rick On Tue, May 26, 2015 at 2:45 PM Michael Ficarra <mficarra at shapesecurity.com> wrote: > Has anyone drafted a proposal for this? Is anyone assigned as champion yet? > > On Tue, May 26, 2015 at 11:05 AM, Rick Waldron <waldron.rick at gmail.com> > wrote: > >> Silence because it wasn't a priority, relative to finishing ES6. It's not >> forgotten and still on track for ES7 development. >> >> Rick >> On Tue, May 26, 2015 at 11:59 AM Gijs Kruitbosch < >> gijskruitbosch at gmail.com> wrote: >> >>> Perhaps surprisingly, I had actually asked around and looked through >>> recent threads. Apologies for not having found the previous discussions >>> from a year ago. It seems that after the call for a strawman in the meeting >>> notes from April 2014, there was silence? >>> https://esdiscuss.org/topic/object-entries-in-2015 asks the same. I >>> don't really know whether it's more useful to continue replying here or >>> pull up that thread (is one month "old" by es-discuss standards?). Either >>> way, it would be useful to know what the current status is, which none of >>> the posts/notes that I saw really clarify. >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >>> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> > > > -- > Shape Security is hiring outstanding individuals. Check us out at *https://shapesecurity.com/jobs/ > <https://shapesecurity.com/jobs/>* > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150527/2245a640/attachment.html>
You can simply use the Symbol.iterator property to configure how you want the property and value of the object to be iterated. This will allow you to use any from of iteration; e.g. For loop while loop forEach if you do the generic way I'm thinking .
If this help. Post me some link to resources that you have found on your journey as a js dev.
You can simply use the Symbol.iterator property to configure how you want the property and value of the object to be iterated. This will allow you to use any from of iteration; e.g. For loop while loop forEach if you do the generic way I'm thinking . If this help. Post me some link to resources that you have found on your journey as a js dev. JS4Lf > On May 27, 2015, at 9:47 AM, Rick Waldron <waldron.rick at gmail.com> wrote: > > No draft written, but I am the current champion. If you'd like to get something started, we can co-champion :) > > Rick >> On Tue, May 26, 2015 at 2:45 PM Michael Ficarra <mficarra at shapesecurity.com> wrote: >> Has anyone drafted a proposal for this? Is anyone assigned as champion yet? >> >>> On Tue, May 26, 2015 at 11:05 AM, Rick Waldron <waldron.rick at gmail.com> wrote: >>> Silence because it wasn't a priority, relative to finishing ES6. It's not forgotten and still on track for ES7 development. >>> >>> Rick >>>> On Tue, May 26, 2015 at 11:59 AM Gijs Kruitbosch <gijskruitbosch at gmail.com> wrote: >>>> Perhaps surprisingly, I had actually asked around and looked through recent threads. Apologies for not having found the previous discussions from a year ago. It seems that after the call for a strawman in the meeting notes from April 2014, there was silence? https://esdiscuss.org/topic/object-entries-in-2015 asks the same. I don't really know whether it's more useful to continue replying here or pull up that thread (is one month "old" by es-discuss standards?). Either way, it would be useful to know what the current status is, which none of the posts/notes that I saw really clarify. >>>> _______________________________________________ >>>> es-discuss mailing list >>>> es-discuss at mozilla.org >>>> https://mail.mozilla.org/listinfo/es-discuss >>> >>> _______________________________________________ >>> es-discuss mailing list >>> es-discuss at mozilla.org >>> https://mail.mozilla.org/listinfo/es-discuss >> >> >> >> -- >> Shape Security is hiring outstanding individuals. Check us out at https://shapesecurity.com/jobs/ > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150527/26278ab1/attachment.html>
Hello,
When writing JS loops over objects, given the environment I'm in, I find myself using the gecko/spidermonkey-only "Iterator()" construct a lot for loops or array comprehensions:
for (let [key, val] of Iterator(plainJSObject)) { // do stuff with both key and val }
It seems the plan is to remove "Iterator()" (cf. developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator ).
Are there plans to add things like Object.values() (to produce Object.keys(obj).map(k => obj[k]) ) or Object.iterator (Object.keys(obj).map(k => [k, obj[k]])) so as to enable such usecases to
be written easily in ES7 or later? Obviously I can create my own iterator, but it starts to get tedious if I need to do this in every file where I need to iterate over an object's own (enumerable) properties...
(using Maps here is difficult because writing hardcoded nested structures of Maps is not nearly as neat as doing the same with Objects)
Gijs