Am experimenting with an anonymous function :
var a:Object = new Object() ;
a.b = new Function()
a.b =function()
{
trace("hello");
}
trace(a.b())
Output :
hello
undefined
What’s undefined ??
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have two trace statements running:
When you call
trace(a.b())firsta.b()is called.a.bis simply this function:So that runs and outputs “hello”.
Now the second trace (
trace(a.b()) tries to output the result ofa.b(). The problem is that you do not return anything ina.b(), so the result is undefined.Edit: As JonatanHedborg points out in his comment, the line
a.b = new Function()is really not needed as you overwrite it on the next line.If you change this to:
You should now see “hello” as the output.
Alternatively, if you change it to this:
so that you are tracing the value of a.b instead of the value of the result of a.b() then you should see “hello” and “Function function” (or something similar) as the result.