Simulate the 'new' operator in JavaScript
<p>I tried to simulate the 'new' operator in JavaScript in a code like this:</p>

<pre><code>Function.method('new', function ( ) {
    var objPrototype = Object.create(this.prototype);
    var instance = this.apply(objPrototype, arguments);

    return instance;
});
</code></pre>

<p>However, in order to cover all the cases, the return statement should look like this:</p>

<pre><code>return (typeof instance === 'object' &amp;&amp; instance ) || objPrototype;
</code></pre>

<p>Now for the tests:</p>

<pre><code>var SomeClass = function (param1, param2) {
    this.param1 = param1;
    this.param2 = param2;
};

var test1 = String.new('test1'); //in this case, the "instance" variable is an object
var test2 = SomeClass.new('test1', 'test2'); // in this case, the "instance" variable is undefined
</code></pre>

<p>Is this exactly what the 'new' operator does? Is there any case left to cover?</p>
