Here is my event and as you can see I want to send a function with it as a parameter.
onclick="deleteItems('image', 'size', function(){GetImageSize();})"
The delete function is in a js file. In my js file I want to call my GetImageSize() function.
var deleteItems = function(module, controller, callback) {
callback(); // ??????????
}
I want to do this so I can rebuild my table when my ajax call has finished.
Hope you guys can help me
Regards Örvar
-
FYI, the asterisks (*) are not real code. It should work if you just remove them. Or you can do as stated below.Anthony -GISCOE-– Anthony -GISCOE-2010年08月26日 16:30:05 +00:00Commented Aug 26, 2010 at 16:30
-
@Anthony: I removed the asterisks. I guess the OP just wanted to make them italics.Daniel Vassallo– Daniel Vassallo2010年08月26日 16:32:52 +00:00Commented Aug 26, 2010 at 16:32
2 Answers 2
You can refer to the function, without calling it--just don't use the ending parens. The parens mean you're calling the function. In the case of passing the function into another function as a callback you want to leave the parens off. (And you don't need the anonymous function declaration around it.) It should read:
onclick="deleteItems('image', 'size', GetImageSize);"
Comments
JavaScript functions are first class objects. You could store functions in variables and pass them around as arguments to functions. Every function is actually a Function object.
Therefore, if you have a GetImageSize() function, you can simply pass it to the deleteItems() function just like any other variable:
deleteItems('image', 'size', GetImageSize);