Calling superclass methods

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function subClassCustom(sub, parent) {
    sub.prototype = Object.create(parent.prototype);
    sub.prototype._parent = parent.prototype;
    sub.prototype.constructor = sub;
  }
  
  function subClassProtoOf(sub, parent) {
    sub.prototype = Object.create(parent.prototype);
    sub.prototype.constructor = sub;
  }
  
  function point2d(x, y) {
      this.x = x;
      this.y = y;
  }
  
  point2d.prototype.add = function (x,y) {
  	this.x += x;
  	this.y += y;
  };
  
  function point3dCustom(x, y, z) {
      this._parent.constructor.call(this, x, y);
      this.z = z;
  }
  
  subClassCustom(point3dCustom, point2d);
  
  // Custom _parent
  point3dCustom.prototype.add = function (x,y,z) {
  	this.z += z;
  	
  	this._parent.add.call(this, x, y);
  };
  
  function point3dProtoOf (x, y, z) {
  	Object.getPrototypeOf(this.constructor.prototype).constructor.call(this, x, y);
  	this.z = z;
  }
  
  subClassProtoOf(point3dProtoOf, point2d);
  
  point3dProtoOf.prototype.add = function (x,y,z) {
  	this.z += z;
  	
  	Object.getPrototypeOf(this.constructor.prototype).add.call(this,x,y);
  };
  
  var pCustom;
  var pProtoOf;
  

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Custom property
pCustom = new point3dCustom(1,2,3);
pCustom.add(1,2,3);
pending…
Using getPrototypeOf ugliness
pProtoOf = new point3dProtoOf(1,2,3);
pProtoOf.add(1,2,3);
pending…

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

Compare results of other browsers

0 Comments