Extend Function

function extend(destination, source) {
  for (var k in source) {
    if (source.hasOwnProperty(k)) {
      destination[k] = source[k];
    }
  }
  return destination; 
}

This is a vanilla JavaScript version of extend however it does not work for symbol-keyed properties (because symbols are not visible in for…in iterations.
With JavaScript 2015 (ES6) there is a new way to achieve this with a new native function on the Object type called assign.

Add your comment