Building an object on the fly and inject a variable
<p>I am writing a JavaScript method that should do:</p>

<ol>
<li>Create an object of a type that has been passed as first argument,</li>
<li>put a variable into that new object and</li>
<li>call the method __construct of that object and pass the arguments to it passed to this method (except for the first).</li>
</ol>

<p>Example usage:</p>

<pre><code>this.create('Foo', 'bar', 42);
</code></pre>

<p>Should do:</p>

<pre><code>var O = new Foo;
Foo.Application = this;
Foo.__construct('bar', 42);
</code></pre>

<p>What I have now:</p>

<pre><code>Application.prototype.create = function(sType)
{
    var Self = this;
    eval('var Object = new ' + sType + ';');

    // what to write here?

    var aParameters = Array.prototype.slice.call(arguments, 1);
    Object.__construct.apply(aParameters);
}
</code></pre>

<p>I tried to inject the Application var into the new object with the following codes:</p>

<pre><code>Object.Application = this;
</code></pre>

<p>or:</p>

<pre><code>var Self = this;
$.extend(Object, { Application: eval(Self) });
</code></pre>

<p>But in the __construct method this.Application is still undefined.</p>
