Jangaroo for Native Speakers of ActionScript
Jangaroo is a subset of the ActionScript 3 language. It supports the following concepts of ActionScript that go beyond ordinary JavaScript:
- classes including private and static members
- packages
- interfaces
- imports
- type annotations
- include directives
The following concepts are not (yet) or only partially supported:
- the with statement
- multiple class declarations in one file (helper classes)
- other member visibilities (internal, protected) and custom namespaces are syntactically accepted but ignored
- XML initializers and query operators (E4X)
- annotations (syntactically accepted but ignored)
- getter and setter functions are not supported by older browsers and Internet Explorer
The definition of package-scoped functions is supported syntactically for the definition of ActionScript 3 APIs, but the compiler cannot generate runtime code for these yet. As a workaround (until we implement this feature), you may write your package-scoped functions in JavaScript and provide an ActionScript 3 API for it. We do this extensively within the Jangaroo runtime and libraries.
With-Statement
The missing with statement may come unexpected, because that is already available in JavaScript. However, the dynamic scoping provided by the with statement does not mix well with the statically scoped class-based approach of ActionScript 3. Maybe we will allow using with in a future release, but its use will always be discouraged.
Semicolons
Jangaroo's syntax is more strict than ActionScript 3 in the placement of semicolons: It requires the correct termination of statements with a semicolon.
Getter and Setter Functions
Jangaroo understands ActionScript getter and setter function syntax, which, for example, may look like this:
package {
public class Field {
private var val : String;
public function Field(value : String) {
val = value;
}public function get value() : String {
return val;
}public function set value(v : String) : void {
val = v;
}}
At runtime, Jangaroo tries to define these methods using the predefined Object methods __defineGetter__ and __defineSetter__. For a description of the feature (using the same example) and its current implementation state in browsers and Rhino, see John Reisig's excellent summary. To conclude, the feature is supported in all modern browsers (Firefox, Safari, Chrome, Opera) and Rhino, but not (yet) in Internet Explorer. IE8 supports something similar, but only for DOM objects.
To keep your code browser-independent, we currently discourage using getter and setter functions, but use getValue() and setValue() methods instead. However, if you can require the clients not to use IE and/or you want to port existing AS3 code with as few changes as possible, using the feature is an option.
We are currently investigating a way to let the compiler generate special emulation code for IE 7 and 8. Note that the current pre-release of Internet Explorer 9 does include support for getter and setter functions.
Further Limitations
Further notes on the current state of implementation can be found in the section on Jangaroo's limitations.