Is it possible to set the ‘this’ or caller of a function yet set that as a callback?
this.CallServer({ url: 'myurl', success: F.call(myDOMElement) });
F function(data){ $(this).text(data); }
I realize that I can wrap the callback function and pass the DOMElement as a param calling F like below but I was wondering if there is a way to do it closer to above.
this.CallServer({url: 'myurl', success: function(data){F(data, myDOMElement);}});
F function(data, elem){ $(elem).text(data); }
bindwill return the same function, except that it has a fixed value ofthiswhenever called.Docs, including shim for older browsers.
Simply speaking,
bindcould be defined as:E.g.