ECMAScript 5 supports a method for Arrays called reduce().
Yes, the variable a is an array, freshly generated by a call to arrayfromargs(arguments).
I suppose I’ll have to use forEach or [gasp!] a plain-vanilla for loop to get the result I want. Or am I missing something? As in: is there any way to get the js object to grok Array.reduce()?
Most other ECMAScript 5 methods are supported by, so I was a bit surprised about this.
PS: If Max6 will take care of this issue, that would also be useful to know.
My favourite would be Underscore.js – http://documentcloud.github.com/underscore/
I can’t guarantee this will work but I am 99% certain underscore has no reliance on the DOM so it should!
Let us know how you get on :)
OK, I was focusing on the ECMAScript version; ECMAScript 5 introduces all the nifty Array methods. Need to pay more attention to what the different JScript levels support.
Since there is currently only one place in my code where Array.reduce() would have been really nice to have, I’ve simply written a plain-vanilla for loop instead. Nothing against added libraries, but time and place…
Array.reduce() works great in Max 6…
Nice to know. The other question, of course, would be « quand arrive-t-il ? » but I last time I looked there’s no ETA.
according to the announcement it’s arriving this fall, that should narrow it down ;-)
Oh, there it is. Right at the top. Last place I look for that sort of thing. C’est ma faute.
Later down I see we’re up to JS 1.8.5. Yummy. (Yes, I know, I used to be disdainful about the language. I still think automatic variable declaration is an absolutely execrable design decision, but there is a lot about the language to like.)