views:

273

answers:

2

I have the following code:

var a= 1 + (function (x) { return x+1;} (2));

This is allowed in JavaScript, but in ActionScript, it's always show an error message, saying this line of code is wrong. I cannot find a documentation on ActionScript about this, anyone has any idea about it?

Thank you in advance!

I have a idea as : var a = 1+(function (x) {return x+1;}).call(function(x) {return x+1;},2); it works fine for this example. and the this is refering to a funciton which is exactly the same as the one before "call" string. the arguments.caller is the location the above "call(..)" happens, and the arguments.callee is refering to the function after "call" string. the arguments.length is 1. En...will this be fine?

It's solved, by modifying the SWF tags.^^

+6  A: 

Try this syntax instead:

var a = 1 + (function (x) { return x+1;})(2);
Daniel Lew
Or, try this code instead: "var a = 4;". WTF is that monstrosity even for? :-)
paxdiablo
I think you guys are missing the point, the questioner posted a trivial example function to illustrate the issue. I highly doubt he actually means to write code like this, I'd guess he just wants to figure out why anonymous inline functions aren't working.
Daniel Lew
yes. Thank you. I want to convert the anonymous inline function into a actionscript. the above code works in JavaScript, and I am doing a JavaScript to ActionScript converting.
+1. But is this syntax limitation of ActionScript documented anywhere? I thought the ECMAScript standard demanded the unbracketed version should work?
bobince
Cannot agree more. I am also curious about the documention. But so far, I didn't find one metioning this kind of situation.
A: 

The "2" is an argument to the function?

IAC: why not break it up and assign the function to a local variable, and pass the variable in. It's easier to understand and debug as well.

Cheers

Richard Haven
Thank you. The above code happens in my test case for compile javascript code into actionscript. If I break up, I need to force my code conversion to put a function definition statement before current line of code. Do you have any suggestion on changing the above code to work locally?