Skip to content

Commit

Permalink
Make Function.prototype.New() faster on v8.
Browse files Browse the repository at this point in the history
  • Loading branch information
cscott committed Jun 14, 2013
1 parent 5655815 commit 8f2150a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion extensions.js
Original file line number Diff line number Diff line change
@@ -11,7 +11,12 @@ var now = function() {
};

// This replaces the 'new' operator.
Function.prototype.New = function() {
Function.prototype.New = function(arg1, arg2) {
// speed optimizations.
if (arguments.length===0) { return new this(); }
if (arguments.length===1) { return new this(arg1); }
if (arguments.length===2) { return new this(arg1, arg2); }
// fully-general implementation.
var object, result;
if (typeof(this.prototype)==="object") {
object = Object.create(this.prototype);

0 comments on commit 8f2150a

Please sign in to comment.