AS3 is a big improvement over AS2. But it feels very 20th century compared to languages like Ruby. For instance, in AS3:
new Array(a, b, c, d).forEach(
function(o:*, idx:int, arr:Array):void {
trace(o);
}, this
);
… is kind of nicer than a for loop, but not much nicer. Why do we need to know the array index and have a reference to the array for every closure? We shouldn’t have to, but we get runtime exceptions if we try to leave those arguments out.
I hanker after elegant, concise syntax like Ruby’s:
[a, b, c, d].each { |o| print o + "\n" }
That’s my thought for the day.




I agree completely.
However, you don’t need to name the second and third arguments explicitly, you can use …rest instead:
function( o:*, …rest ) : void { }
It’s a bit shorter, but still not as terse as Ruby.
Haha, well they don’t have to be that ugly, alot of it is determined by the way you code it. Nevertheless, read this, you might like the topic/tone:
http://gasi.ch/blog/functional-actionscript-part-1/
Joshua,
I totally agree with you. However, there are at least two workarounds for this:
(1) Use a wrapper function. Find out how on my blog:
http://gasi.ch/blog/functional-actionscript-part-2/#wrap
(2) Even more pragmatic is the following method suggested by Theo from Iconara: Use ActionScript’s …rest argument
function( item : *, …ignored ) : * {
// do the magic
}
Regards,
Daniel
Thanks for the link to your post, Daniel. A very interesting read!
Josh