发布于 2013-06-29 04:05:59
文档没有提到它是否读取原型链。
从他们的代码,_.clone
方法,他们使用_.extend
来创建一个浅层拷贝。这可能是_.extend
读取原型链的真正原因……这并不是一个很好的理由。但是,除了传递原始对象之外,我从不使用_.extend
传递任何内容
_.clone需要它的原因示例
function Base(a) {
this.a = a;
}
Base.prototype = {b: 'b'};
var obj = new Base('a')
console.log($.clone({x: 'x'}, obj))
// Most people would expect the output to be
// {x: 'x', a: 'a', b: 'b'}
// If it didn't read the prototype, it would only be
// {x: 'x', a: 'a'}
https://stackoverflow.com/questions/17372450
复制相似问题