Prototype vs Closure Classes

Benchmark created by Matt on


Setup

function ProtoClass() {
      this.x = 0;
      this.y = 0;
    }
    
    ProtoClass.prototype.getX = function() { return this.x; };
    
    ProtoClass.prototype.getY = function() { return this.y; };
    
    
    function ClosureClass() {
      var x = 0;
      var y = 0;
    
      return {
        getX : function() { return x; },
        getY : function() { return y; }
      };
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Using ProtoClass
new ProtoClass();
ready
Using ClosureClass
ClosureClass();
ready

Revisions

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

  • Revision 1: published by Matt on