nothing wrong, that's basically what I do indeed as Object.prototype.forEach but it would be faster done natively
On Thu, Dec 1, 2011 at 7:00 PM, Brendan Eich <[email protected]> wrote: > On Dec 1, 2011, at 8:00 AM, Andrea Giammarchi wrote: > > ... iterators not backward compatible ... a failing solution for me for > this very simple and common problem :-/ > > > What is wrong with the standard combination, which would be the basis for > any polyfill (including a polyfill for Object.keys)? > > js> o = {p:1,q:2,r:3} > ({p:1, q:2, r:3}) > js> Object.keys(o).forEach(function (k) {print (k, o[k])}) > p 1 > q 2 > r 3 > > /be > > > > On Thu, Dec 1, 2011 at 2:04 PM, David Bruant <[email protected]> wrote: > >> Le 01/12/2011 08:47, Andrea Giammarchi a écrit : >> > Let's say this is an attempt to bring some new, easy to implement, >> > method for the native Object.prototype >> > Specially about forEach, the most used Array.prototype method out there, >> That's quite an ambitious statement. I use forEach, but I think I use >> push, concat, every/some, map and reduce quite often as well and I >> wouldn't be able to tell which I use more often (probably push). >> >> > it's quite clear JS developers would like to have similar method to >> > iterate over objects, as key:value pairs rather than index:value. >> It seems that iterators [1] could do what you need. In this proposal (so >> very likely to be in ES.next), you can see this example: >> ----- >> for ([key, val] of items(x)) { >> alert("x." + key + " = " + val); >> } >> ----- >> >> There is even the possibility for you to define your own iterator on >> your objects. >> >> > Almost every framework/library out there has an "error prone" >> > each(obj, callback) method, able to automagically recognize if the >> > passed obj is an array, an arrayLike, or an object. >> > A classic failing scenario is a function used as object, where the >> > length property won't mean it's an arrayLike entity. >> If some library authors think that an array is an object with a 'length' >> property, I think that they should learn JavaScript and that is not a >> reason to add a language feature. >> >> David >> >> [1] http://wiki.ecmascript.org/doku.php?id=harmony:iterators >> > > _______________________________________________ > 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

