Anytime a function is called using a function call * , this set to a global variable (or undefined in strict mode) - even if you call the function from a method, Douglas Crockford actually described it as a flaw in this language.
Storing the this value in a variable that the function will have access to is the standard way to deal with this.
If you really want to control what this in your callback, you can use apply or call . Both take as the first argument that you want to set this . The difference is that apply expects all function arguments to be passed as an array, and call expects you to list them separately.
So, if you wanted to call manageIframeResponse in your ajax manageIframeResponse , give it an answer to the ajax call (I know your example did not pass the answer, I just illustrate how you will do it) and the value of this will be the same as the current object , You can do:
var self = this; $.ajax({ success : function(response){ manageIframeResponse.apply(self, [response]);
Or, since your parameters are not yet in array form, you can simply use call
var self = this; $.ajax({ success : function(response){ manageIframeResponse.call(self, response);
* There are various ways to call a function.
A function call means that you simply call a function that is in your current scope:
foo() //inside foo, this will be the global object (or undefined in strict mode)
A method call means that you are calling a function attached to an object
myObj.foo()
Here's an example of where it might touch you if you're not careful.
function objCreator() { var y = "There"; function privateFunc() { alert(y); //alerts There as expected alert(this.someField); //undefined: whoops - this is the global object, } //so there no someField return { x: "Hi", someField: "blah", foo: function () { alert(this.x); privateFunc(); } }; }