On 2008-09-10, at 22:57EDT, Henry Minsky wrote:

When we have default values like this, something complains in the flex
compiler

function toArray (linkMaker=function (rep, id) {return
Debug.ObjectForID(id);}):Array {

    [java] [/tmp/lzswf9/lzgen27609/LzDebugMessage.as: 188]
debugger/LzMessage.lzs: 200: Error: Parameter initializer unknown or is not
a compile-time constant.

So I have been converting complex initializers like that into null default
args, and initializing in the function body, like this

+  function toArray (linkMaker=null):Array {
+    if (linkMaker == null) {
+      function (rep, id) {return Debug.ObjectForID(id);}

So long as you really meant:

+      linkMaker = function (rep, id) {return Debug.ObjectForID(id);}

I think that's ok.

+    }

The other possibility:

function defaultLinkMaker (rep, id) {return Debug.ObjectForID(id);}

function toArray(linkMaker=defaultLinkMaker) ...

Personally, I think Flex's restrictions on what can be in a default value are a bug. You aren't allowed to have any sort of expression at all, you can't default a parameter based on a preceding parameter, etc. Too bad.

Reply via email to