Unfortunately, there is no parent-child relationship between objects in JavaScript. The reason for this is that it is possible for the same object to have multiple parents. This can be difficult to grasp when you are dealing with nested objects (as is the case in the code example you have provided). Consider the following example:
var foo = {
bar: {
baz: 1,
biz: function() { console.log(this) }
}
}
foo.bar.biz();
=> { baz: 1, biz: [Function] }
var y = {};
y.foobar = foo.bar
y.foobar.biz();
=> { baz: 1, biz: [Function] }
In both cases, a call to biz
will return only the immediately containing object. To attempt to access the parent of the bar
object through the this
keyword would be ambiguous because there are multiple parents that have been specified.
In your case, your best option would be to use the call
function to explicitly specify the function context:
var $target = $('.target');
$.fn.Response.Hello.call($target);