function myFunction(...rest)
syntax. This way I can pass in no parameters (in which case rest is an empty array), one parameter, or multiple parameters.But, then I wanted to pass those same parameters on to another function that also accepted a variable number of parameters (e.g. ExternalInterface.call(jsFunctionName, ...args)). If you simply call the other function and pass in rest as a parameter then it won't work as expected. E.g.
public function sayHello(...rest):void { |
What happens in
callMe(...rest)
is rest
is an array that actually contains only one item - another array which has the rest parameters that were originally passed into sayHello(...rest)
.So if you made a call like this:
sayHello("Hello", "World", "!"); |
Notice that there is only 1 parameter!
The way to get around this is to use Function.apply(null, args) to call the function instead, like this:
public function sayHello2(...rest):void { |
So if you made this call now:
sayHello2("Hello", "World", "!"); |
Now there are 3 parameters as expected.
I found some help on this topic from The Joy Of Flex Blog by David Colleta.
2 comments:
hi Chris,
Your posts are good and clear. I follow all ur flex posts.
I know it is a wrong query here. But I dont have other option. Excuse me.
I am new to blogging.So, Can you please share how do you post code snippets in your blogs.
It will be great, if you can point me to right sources. I googled for more than 3 hrs. I didn't find any thing good.
Hi there,
I actually have a blog post explaining how it post my code snippets with syntax highlighting:
http://flexdevtips.blogspot.com/2009/05/blogger-source-code-syntax-highlighting.html
Chris
Post a Comment