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