0

This might have been asked before, but I can't find any good examples on how to accomplish this.

I have a callback which is fired. But inside this callback i need to add a new parameter to the ending callback function. How can I do this:

var form_to_submit = function() {    
   var parameters = {
       param1 : "1",
       param2 : "2"  
   }
   // do_something with the parameters
}

first_function(form_to_submit);

function first_function(form_to_submit) {
   if($.isFunction(form_to_submit)) {
       var token = "new parameter"; // this parameter should be added to parameters in form_to_submit()
       form_to_submit(); // need to pass on the token to this function call
   }
}
4
  • 4
    Why can't you just pass the parameter? This question is not very clear. Commented Nov 9, 2011 at 13:57
  • Updated, the question, to clarify Commented Nov 9, 2011 at 14:02
  • Still makes no sense. Why are you declaring "parameters" like that? If you want the function to take parameters, you should declare it with parameters. Commented Nov 9, 2011 at 14:06
  • The parameters in form_to_submit is set within this function for a reason, the new parameter in first_function is added after some security checks have been made. My example is a stripped down version of the entire code, but the logic is the same. Commented Nov 9, 2011 at 14:13

1 Answer 1

2
if($.isFunction(form_to_submit)) {
   var token = data['token'];
   form_to_submit(token); // need to pass on the token to this function call
} else {
   form_to_submit.submit();
}

I think the syntax you are looking for is that of the above. You don't need to modify the if($.isFunction(form_to_submit)) line because all you're telling it is to use that function. At that point it doesn't care about parameters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.