【发布时间】:2013-02-25 21:47:50
【问题描述】:
这里是 _.extend from underscore。
// Extend a given object with all the properties in passed-in object(s).
_.extend = function(obj) {
each(slice.call(arguments, 1), function(source) {
if (source) {
for (var prop in source) {
obj[prop] = source[prop];
}
}
});
return obj;
};
函数 call 需要一个 this 值,后跟一个参数列表。
如果传递的唯一参数是 '1',那么 slice 将返回一个省略第一项的数组。
但是,如何将参数用作我的 MDN 定义的 this 值。
MDN
【问题讨论】:
-
任何对象都可以用作
this的值,甚至是null。 -
arguments是一个类似数组的对象,包含对传递给函数的每个参数的引用。
标签: javascript