What does 'this' refer to in call back function inside the module pattern
<p>In <code>Ajax.use</code>, inside the callback function this refers to the callback function.</p>

<p>However outside of a callback definition <code>this</code> would refer to a particular instance of Ajax.</p>

<p>That is how I use <code>this</code> in <code>Ajax.invoke</code> -> <code>this.use()</code> to call a member method from another member method.  </p>

<p>I need to call a member method inside of the callback function as well.</p>

<p>I guessed and put in </p>

<pre><code>this.invoke()
</code></pre>

<p>but I dont' think this is referring to the correct object as it is in the callback function.  I think it refers to the callback function object.</p>

<pre><code>/**
 *    Ajax
 */

var Ajax = ( function () 
{
    var Ajax = function (element) 
    {
        this.object = this.create();
    };
    Ajax.prototype.create = function() 
    {
        var request;
        try
        {
            request = new window.XMLHttpRequest();
        }
        catch( error )
        {
            try 
            {
                request = new window.ActiveXObject( "Msxml2.XMLHTTP" );
            }
            catch( error )
            {
                try
                {
                    request = new window.ActiveXObject( "Microsoft.XMLHTTP" );
                }
                catch( error )
                {
                    request = false;
                }
            }
        }
        // alert("Object Created Successfully");
        return request;
    };

    Ajax.prototype.use = function( param, ajax_func )
    {
        alert("Ajax.prototype.use Called");
        this.object.open( "POST", Global.GATEWAY, true );
        this.object.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
        this.object.setRequestHeader( "Content-length", param.length );
        this.object.setRequestHeader( "Connection", "close" );
        this.object.onreadystatechange = function()
        {
            if( this.readyState === 4 )
            {
                if( this.status === 200 )
                {
                    ajax_func( this.responseText );
                    return true;
                }
                else
                {
                    this.invoke( param, ajax_func );
                    return false;
                }
            }
        };
        this.object.send( param );
        return true;
    };

    Ajax.prototype.invoke = function( param, ajax_func )
    {
        var state = false,
            count = 1;
        while( state === false &amp;&amp; count &lt;= 5 )
        {
            if( count !== 1 )
            {
                alert( 'Ajax Object Use Failed | Try Again ');
            }
            state = this.use( param, ajax_func );
            count++;
        }
        return state;
    };

    return Ajax;

} () );
</code></pre>
