Prototype vs. this (v13)

Revision 13 of this benchmark created on


Setup

function T1() {
      this.x = 0;
    }
    
    T1.prototype.myMethod = function() {
      this.x = this.x +1;
    };
    
    function T2() {
      this.x = 0;
      this.myMethod = function() {
    
      this.x = this.x +1;
      };
    }
    
    var t1 = new T1;
    var t2 = new T2;

Test runner

Ready to run.

Testing in
TestOps/sec
Using prototype
t1.myMethod();
ready
Using this
t2.myMethod();
ready

Revisions

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