> In flash you can do conditional compilation, you can define a boolean
> variable and wrap code in statements like this:
>
> CONFIG::MyVariable
> {
> //Code to include if MyVariable is true
>
> }
>
> I think this would be very useful for maintaining one code base to
> compile to multiple targets as anything I know needs to be different
> in the browser can be wrapped inside conditional compilation.
Sounds like a good feature to add! Do you have any pointer to where
conditional compilation in Flash is documented officially?
Unfortunately, IntelliJ IDEA 9 does not seem to support the syntax you
mention. :-(
> I find myself writing a lot of global functions which I implement in
> regular javascript to get around type errors when I am using a browser/
> lib feature not defined with an AS3 interface. It would be nice if I
> could specify a block of code to not be validated / compiled so
> regular JS can be inserted into an AS3 function.
We chose ActionScript instead of e.g. Java (=> GWT) to compile to
JavaScript, because they are so similar. You can almost paste any
JavaScript code into an AS3 function body and compile it with
Jangaroo, there are only a few things to be aware of:
* To access global JavaScript identifiers (variables, functions), use
window.foo or window['foo'], not just foo.
* Generally, use obj['foo'] if obj.foo leads to a type error.
* Take care when using 'this' in a function inside a non-static
method: Jangaroo will bind the inner function's 'this' to the outer
object. To prevent this, define the inner function inside a static
method.
* Note that static code is not executed immediately, only when the
class is actually used. Trigger by calling a static method from
JavaScript in your bootstrap code.
> Finally I can see a performance advantage to introducing macros into
> the compiler. If I want to support a feature such as the external
> interface i would end up writing something like this:
>
> class ExternalInterface
> {
> public static function call(...args){
> eval(args[0] + "("........
> }
>
> }
>
> This doesn't really make sense, the code goes through class lookup,
> closure wrappers, the call function and an eval before it can execute
> javascript which could have been executed in line. With a macro system
> a macro could be defined to replace ExternalInterface.call with just
> the javascript code.
>
> e.g.
>
> ExternalInterface.call("foo", "bah"); -> foo("bah");
You should not use eval(), because it is "evil" (performance,
security, debugging, ...). Instead, use Function#apply, like so:
public static function call(functionName:String, ... arguments):* {
return window[functionName] ? window[functionName].apply(null,
arguments) : null;
}
I don't see a need for compiler macros, and honestly don't like them.
Reminds me too much of C preprocessor...
Greetings,
-Frank-