How to access JavaScript object that WidgetFactory instantiates

How to access JavaScript object that WidgetFactory instantiates

Hi guys,

Thanks for all the great work you do on JQuery UI!

I'm trying to access the JavaScript object that WidgetFactory instantiates and wraps around my DOM element. I tried:

1. Calling my widget method with no args, but that returns the DOM element
2. Calling http://api.jqueryui.com/jQuery.widget/#method-widget but that returns the DOM element
3. Adding a new method 'returnThis' but JQuery appears to mangle that somehow? See code below, and fiddle here: http://jsfiddle.net/MfegM/521

I've found I can return 'this' if I wrap it in an array, and then JQuery does not mangle it. But presumably there is a proper way to do this?

--- JavaScript code ---

$.widget( "custom.returnThis", {
   
    getThis: function() {
   
        console.log( "Inside here, 'this' is" );
        console.log( this );
        return this;
    },
} );

$( '#returnThis' ).returnThis();
var returned = $( '#returnThis' ).returnThis( "getThis" );

console.log( "But outside, 'this' becomes" );
console.log( returned );