On 1/27/07, Tom W.M. <[EMAIL PROTECTED]> wrote:
> >>> var dataArr = new Array();
> >>>   forEach(rData, function(rRow) {
> >>>     dataArr.push(values(rRow));
> >>>   });
> >> Yes there is: var dataArr = map(values, rData);
>
> It's a bad idea to use either of these solutions, since JavaScript
> object properties are not ordered.  While it may happen to be that the
> keys produced by a ``for (k in o)`` (as in ``keys(o)`` and ``items(o)``)
> loop are produced in a stable order in current browsers, it should not
> be counted on.  If some browser changes their implementation, the
> columns in your table may change order or even contain data that belongs
> in other columns.  This is also asking for cross-browser differences, as
> different JavaScript implementations are likely to differ on this point.
>
> You should incorporate an array of the keys into either your code or the
> data structure so that you can access them in the correct order.

Tom is absolutely right.

To ease cases like this, maybe we should have a utility function in
base like getItems:

function getItems(keys, obj) {
    return map(function (key) { return obj[key]; }, keys);
}

especially intended for stuff like partial(getItems, ['firstname', 'lastname']).

...or maybe just extend itemgetter to accept an array as a parameter, so that
itemgetter(['x','y'])({'x':10, 'y': 20}) == [10, 20]

Arnar

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to