JS and OOP (v5)

Revision 5 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
Constructor
function myObject() {
  this.iAm = 'an object';
  this.whatAmI = function() {
    alert('I am ' + this.iAm);
  };
};

myObject.prototype.run = function(){
   this.whatAmI();
};
myObject.run();
ready
Literal
var myObject = {
  iAm: 'an object',
  whatAmI: function() {
    alert('I am ' + this.iAm);
  }
}

myObject.run = function(){
   this.whatAmI();
};

myObject.run();
ready
Class
myObject = function() {
  this.iAm = 'an object';
  this.whatAmI = function() {
    alert('I am ' + this.iAm);
  };
};

myObject.prototype.run = function(){
   this.whatAmI();
};
myObject.run();
ready
Class prototype
myObject = function() {

};

myObject.prototype.iAm = 'an object';
myObject.prototype.whatAmI = function() {
  alert('I am ' + this.iAm);
};

myObject.prototype.run = function(){
   this.whatAmI();
};

myObject.run();
ready
Class prototype ref
var iAm = 'an object';
var whatAmI = function() {
  alert('I am ' + this.iAm);
};

myObject = function() {

};

myObject.prototype.iAm = iAm;
myObject.prototype.whatAmI = whatAmI;

myObject.prototype.run = function(){
   this.whatAmI();
};

myObject.run();
ready
Class ref
whatAmI = function() {
  alert('I am ' + this.iAm);
};

myObject = function(whatAmI) {
  this.iAm = 'an object';
  this.whatAmI = whatAmI;
};

myObject.prototype.run = function(){
   this.whatAmI();
};

myObject.run();
ready

Revisions

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