jQuery UI widget factory: how to reference widget instance using 'this' inside a options?

204 views Asked by At

I have the following code snippet:

$.widget("tj.commonCoordinator", {
    options: {
        "obx_type": "common_obx",
        "obx_callbacks": {
            request_modify: function(event, ui) {
                this._loadentries();
            },
        }
    },

    _loadentries: function(){}
});

Note that inside the options object, there is a request_modify anonymous function. Inside that function I'm using this to reference the currently initiated widget instance, but failed. In this broken code the this references to the window as it is just an anonymous function.

What is the best way to make this inside a options object of the Widget factory prototype reference correctly to the widget instance? Thanks.

1

There are 1 answers

0
Viktor A. On

Maybe you can use the proxy() method to do this:

$.proxy(this._loadentries, this)