9.5. Function LiteralsActionScript allows us to create function literals, which are convenient when we need a function temporarily or when we'd like to use a function where an expression is expected. Function literals have the same syntax as standard function declarations except that the function name is omitted and there's a semicolon after the statement block. The general form is:
where param1,param2,...paramn is an optional list of parameters and statements is one or more statements that constitute the function body. Because it doesn't include a function name, a function literal is "lost" unless we store it in a variable (or an array element or object property). We can store a function literal in a variable for later access, like this:
Note that because ActionScript does not support JavaScript's Function( ) constructor, dynamic functions cannot be composed at runtime, as they can in JavaScript.
Copyright © 2002 O'Reilly & Associates. All rights reserved. |
|