Prototype vs object.

Benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Returned object.
var Thing = function () {
  var privateVar = "";

  return {
     publicMethod: function () {
        return "thing";
     }
  }
};

var item = new Thing();
item.publicMethod();
ready
Prototype.
var Thing = function () {
   this.someVar = "";
};

Thing.prototype = {
   constructor: Thing,
   publicMethod: function () {
      return "thing";
   }
};

var item = new Thing();
item.publicMethod();
ready
Assignment in consturct
var Thing = function () {
   this.someVar = "";

   this.publicMethod = function () {
      return "thing";
   }
};

var item = new Thing();
item.publicMethod();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.