If you end the jquery function call with $ .proxy (function, this), then jquery will correct your link to this so that it works the way you want.
Firstly, your question is right. However, your code does not work, and when it is fixed, it illustrates the solution to the problem. Short lesson: you will learn more if you debug your problem code first!
Below I will pose a problem, a solution that you will illustrate, and a more elegant solution.
Here is the object in question:
var aObject = { aVariable : 'whatever value', test : function() {
Here is an example of a problem:
var anInstanceOfAObject = $.extend({}, aObject); anInstanceOfAObject.someFunction = function() { $(function() {
Here is your solution:
var anInstanceOfAObject = $.extend({}, aObject); anInstanceOfAObject.someFunction = function() {
Finally, here is a slightly more elegant answer:
var anInstanceOfAObject = $.extend({}, aObject); anInstanceOfAObject.someFunction = function() { $( $.proxy(function(){
source share