I'm working with a fairly complex Javascript program wich, at a given point, returns some nested anonymous functions.
Sometimes, when I try to "apply" one of such anonymous functions ("f" in this example)...
f.apply (this.context, args)
...I get an "f.apply is not a function" error.
It's weird, because alert(f) displays the function source code but typeof(f) returns "object" (not "function").
alert (f) --> displays "function (input) { self.checkToken (input, regex, callback) }"
Also, f.call and f.apply are undefined.
Checking the typeof(f) at some stages of execution always returns "function". I can't explain why, when I need to call the funct开发者_如何学Cion, it casts to object.
I've tested the code against Firefox and Microsoft JScript engine, obtaining the same results.
Maybe I'm missing some basic aspect of Javascript anonymous blocks? :-\
Oh! Mea culpa...
I realized I was returning the function inside an array of length 1, so "alert()" showed the first object's toString representation.
Mystery resolved and public shame on me :)
精彩评论