Flash as3: creating anonymous objects when calling a function?

If I want to send a function object with one child called foo equals "bar", I need to do the following:

var obj:Object = new Object();
obj.foo="bar";
myfunction(obj);

Is there a way to declare an object in a function itself? something like that:

myfunction(new Object{foo:"bar"}); 

Thank you!

using flash-as3.

+3
source share
1 answer

You almost had it in your example!

To create an inline object, you use curly braces:

myfunction({foo:"bar"});

You can also do inline arrays with parentheses:

myfunction(["bar", "baz"]);
+18
source

Source: https://habr.com/ru/post/1732780/


All Articles