2

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

Daniel Vassallo
346k72 gold badges514 silver badges447 bronze badges
asked Aug 26, 2010 at 16:20
2
  • FYI, the asterisks (*) are not real code. It should work if you just remove them. Or you can do as stated below. Commented Aug 26, 2010 at 16:30
  • @Anthony: I removed the asterisks. I guess the OP just wanted to make them italics. Commented Aug 26, 2010 at 16:32

2 Answers 2

3

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);"
answered Aug 26, 2010 at 16:22
Sign up to request clarification or add additional context in comments.

Comments

3

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);
answered Aug 26, 2010 at 16:30

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.