JS Object Creation

JavaScript performance comparison

Revision 3 of this test case created

Info

Creating custom objects with hidden state and public mutators.

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
NO prototype - public mutators
function Person(config) {
  var state = config || {};

  this.set = function(key, value) {
    state[key] = value;
  };
};

var me = new Person;
me.set("name", "Joshua");
pending…
Use hidden function and "apply"
var Person = (function() {
  var hidden = function(key, value) {
      this[key] = value;
      };

  return function(config) {
    var state = config || {};

    this.set = function(key, value) {
      hidden.apply(state, arguments);
    };
  };
}());

var me = new Person;
me.set("Name", "Joshua");
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment