Extending object es5

JavaScript performance comparison

Test case created by Cezary Tomczyk

Preparation code

<script>
  var extend_for_in = function(destination, source) {
      var key;
      for (key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          destination[key] = source[key];
        }
      }
      return destination;
      };

  var extend_for_each = function(destination, source) {
      Object.keys(source).forEach(function(key) {
        destination[key] = source[key];
      }, destination);
      return destination;
      };

  var obj1 = {
    o1: 1,
    o2: 2,
    o3: 3,
    o4: 4,
    o5: 5
  },
      obj2 = {
      oo1: 1,
      oo2: 2,
      oo3: 3,
      oo4: 4,
      oo5: 5
      };
</script>
    

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
for-in
extend_for_in(obj1, obj2);
pending…
for-each
extend_for_each(obj1, obj2);
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