ActionScript 3 Language Specification |
|||
| ActionScript 3.0 Language Specification > 1 Tutorial introduction > 1.5 Functions | |||
Functions define properties whose values can be called. An example of a function follows:
function hello() {
trace("hello, world")
}
hello()
Depending on where a function is defined, it results in a property whose value is a function closure or a method. A function closure is a first class object that can be treated as a collection of properties or a callable object. A method is tightly bound to the object that it is associated with. The this reference of a function is bound to the base object of the call expression, or the global object if none is specified.
function hello() {
trace("hello, world")
trace(this) // this refers to global object
}
hello()
A method is a function that is tightly bound to an object. A method can be extracted from its instance, but, unlike function closures, the value of this always refers to the instance it is extracted from.
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/specs/actionscript/3/as3_specification7.html