Consider this normal example.
function greetings():void
{
trace( "Hello World" );
}
greetings();
This will display "Hello World"
.
The above example can be written in more elegant way (i.e., self invoking the function) as:
(function greetings():void {
trace( "Hello World" );
})();
You get the same result. It's a function expression. Function expression syntax is of the form:
( f )();
Another example:
(function greetUser( name:String ):void {
trace( "Hello " + name );
})("Awesome");
You pass an argument during self invocation.
However one important thing you must consider is the scope.
(function greetUser( name:String ):void {
trace( "Hello " + name );
})("Awesome");
greetUser( "Foo" ); // will result in error
So note that.