Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A faster way to extend #1

Open
tjbenton opened this issue May 16, 2015 · 0 comments
Open

A faster way to extend #1

tjbenton opened this issue May 16, 2015 · 0 comments

Comments

@tjbenton
Copy link

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;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant