Sunday, 15 August 2010

Javascript cast from object to function -


Suppose I have a JavaScript function of the form:

  function () {warning ( Suppose I also have an applet, in which there is a method called Dustfile which takes the function as a parameter:  
  MyApplet. DoStuff (function () {warnings ("blah ");});  

Now suppose that the applet function gives success or failure javascript callback function based on the results of its calculations A. In the callback function, I want to execute function have to throw users to get my highly informative "blah" message:

  function callback (function) {()); }  

However, in the above example, the function is no longer considered the "function" type (the type of the "object" will return the type). Is the function possible to change the function, so that it can be executed? I have many hacks that can give me what I want, but they are very ugly and I was hoping that I was missing some simple.

Any help is greatly appreciated.

/ Div>

Try func.call ()


No comments:

Post a Comment