Method Inheritance

JavaScript performance comparison

Test case created by Joshua T Kalis

Info

Using prototypes for method inheritance or on the object directly.

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Prototypal
function Obj(config) {
  for (var i in config) {
    this[i] = config[i];
  }
}
Obj.prototype.attr = function(str, val) {
  return val ? this[str] = val : this;
};

var n = new Obj({
  age: 33,
  name: "Joshua"
});
n.attr("age", 33);
n.attr("age");
pending…
Direct
function Obj(config) {
  for (var i in config) {
    this[i] = config[i];
  }
  this.attr = function(str, val) {
    return val ? this[str] = val : this;
  };
}

var n = new Obj({
  age: 33,
  name: "Joshua"
});
n.attr("age", 33);
n.attr("age");
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

Add a comment