JavaScript how to have class inside namespace
<p>I'd like to define a class type inside my namespace, but I can't think how to do this so that the 'this' command referes to the instance of the class and not the 'this' of the namespace.</p>

<p>It will make more sense if I provide the example where I need to do this. I'm creating some JavaScript code to convert all forms to submit via Ajax instead, then if the Ajax request fails it attempts to submit the form again after a period of time. The thinking is so that the page will still work if the users internet connection drops.</p>

<p>Code</p>

<pre><code>// Add event handlers to capture form submit events here (code not shown)

// Use this object as a namespace
var AjaxStack_f = function () {}

// Use this as a struct/class for defining requests (This is what I don't like)
function Request(url, data, method) {
    this.url = url;
    this.data = data;
    this.method = method;
}

// The stack of Requests
AjaxStack_f.prototype.stack = [];

// Push a Request on to the stack
AjaxStack_f.prototype.push = function(request){
    this.stack.push(request);
}

// Provide instance
var AjaxStack = new AjaxStack_f();
</code></pre>

<p>Using the above I can do what I want to do with this code</p>

<pre><code>var request1 = new Request("www.example.com", { value: 1 }, "get");
var request2 = new Request("www.anotherurl.com", { value: 2 }, "get");
AjaxStack.push(request1);
AjaxStack.push(request2);
</code></pre>

<p>How can I put the Request class inside the AjaxStack namespace so that I can do something like this instead</p>

<pre><code>var request1 = new AjaxStack.Request("www.example.com", { value: 1 }, "get");
var request2 = new AjaxStack.Request("www.anotherurl.com", { value: 2 }, "get");
AjaxStack.push(request1);
AjaxStack.push(request2);
</code></pre>
