JS Object Creation (v3)

Revision 3 of this benchmark created on


Description

Creating custom objects with hidden state and public mutators.

Test runner

Ready to run.

Testing in
TestOps/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");
ready
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");
ready

Revisions

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