Parenthesis has a really interesting field of application in AS3.
Have a look at this page: Parentheses
The interesting one is to evaluate a series of expressions:
var a:int = 2; var b:int = 3; trace((a++, b++, a+b)); // 7 |
Very cool stuff it looks like an inlined function. Normally I would write something less creative like this
function foo(a:int, b:int):int{ a++; b++; return a+b; } trace(foo(2,3)); // 7 |
I also would say that second version is more readable and reusable, but not as cool as the first one.
Another interesting thing about this notation is that you can’t declare variables inside parenthesis, but you can declare anonymous functions:
var f:Function; trace((f = function():int{return 7;}, f())); // 7 |
And that’s not all folks. There is another context where parenthesis have a pretty cool role - E4X. In E4X you use parenthesis for “filters” declaration.
There are a few nice posts about E4X filters on this blog: http://joshblog.net/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/
Place your comment