Inheritance: __proto__ vs object.create

JavaScript performance comparison

Test case created by remove

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
__proto__
function ParentObj() {
  this.total = 1+1
}
ParentObj.prototype = {
  name: "Kevin",
  age: 100,
  awesome: true
}

function ChildObj() {
  ParentObj.apply(this, arguments);
}
ChildObj.prototype = {
  __proto__: ParentObj.prototype,
  job: "engineer",
  mood: "hungry"
}

var myobj = new ChildObj()
pending…
Object.create
var ParentObj = {
  init: function() {
    this.total = 1+1
  },
  name: "Kevin",
  age: 100,
  awesome: true
}

var ChildObj = {
    init: {
      value: function() {
        ParentObj.init.apply(this, arguments)
      }
    },
    job:{
      value: "engineer"
    },
    mood: {
      value: "hungry"
    }
  }
  
var child = Object.create(ParentObj, ChildObj).init()
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