JavaScript Scope Chain (v6)

Revision 6 of this benchmark created on


Description

Test case for which access method is fastest in relation to the JavaScript scope chain.

Test runner

Ready to run.

Testing in
TestOps/sec
Private variables
(function(window) {
  var local = 0;

  window.obj = {
    test: function() {
      return local;
    }
  };
})(window);

obj.test();
ready
Using 'this'
(function(window) {
  window.obj = {
    local: 0,
    test: function() {
      return this.local;
    }
  };
})(window);

obj.test();
ready
Using 'this' and return object
window.obj = (function() {
  return {
    local: 0,
    test: function() {
      return this.local;
    }
  };
})();

obj.test();
ready
Global variables
var global = 0;
(function(window) {
  window.obj = {
    test: function() {
      return global;
    }
  };
})(window);

obj.test();
ready
Local variables
(function(window) {
  window.obj = {
    test: function() {
      var local = 0;
      return local;
    }
  };
})(window);

obj.test();
ready

Revisions

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