Skip to content

A faster way to extend #1

Open
Open
@tjbenton

Description

@tjbenton

This isn't really an issue but I figured I'd let you know what I found on the js perf tests when using a for loop instead of a forEach

Here is the js perf tests http://jsperf.com/deep-extend-comparison

function extend(a, b){
 // Don't touch 'null' or 'undefined' objects.
 if(!a || !b){
  return a;
 }

 var keys = Object.keys(b);

 for (var i = 0, l = keys.length; i < l; i++){
  var key = keys[i];

  // Detect object without array, date or null.
  if(Object.prototype.toString.call(b[key]) === "[object Object]"){
   if(Object.prototype.toString.call(a[key]) !== "[object Object]"){
    a[key] = b[key];
   }else{
    a[key] = extend(a[key], b[key]);
   }
  }else{
   a[key] = b[key];
  }
 }
 return a;
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions