Copy all of the properties in the source objects over to the destination object, and return the destination object. It's in-order, so the last source will override properties of the same name in previous arguments.
将源对象属性复制到目标对象,并返回目标对象。它是有序的,所以最后的来源将覆盖以前参数名称相同的属性。
1 _.extend({name : 'moe'}, {age : 50}); 2 => {name : 'moe', age : 50}
源码:
1 _.extend = function(obj) { 2 each(slice.call(arguments, 1), function(source) { 3 for (var prop in source) { 4 obj[prop] = source[prop]; 5 } 6 }); 7 return obj; 8 };