JavaScript Anonymous Function With Parameters From Call()

I am trying to do the following:

function main(callback) {
   $.ajax('server-side', function() {
       this.callback.call("hello");
   }.bind({ callback: callback });
}

main(function(response) {
   alert(response);
});

Response is undefined, I would expect it to be "hello". Any ideas why?

Answers


call first argument should be a reference to "this". Being "this" the context where you want to execute your function. Call function Mozila MDN


Need Your Help

split and strip elements in list python

python file list strip

words is a list which look something like this:

JLabel doesn't show a long paragraph

java swing user-interface jlabel

How can I enable the JLabel to show the whole paragraph?