有什么区别
Employee.prototype = Object.create(Person.prototype);
和
_.extend(Employee.prototype, Person.prototype);
两者都给出了相似的结果(输出),但是下划线方法似乎将 Person.prototype 添加到 Employee.constructor.prototype 中,并且到处都是额外的东西,为什么?
纯JS
下划线JS
一个很好的副作用_.extend
是我可以轻松地进行多重继承:似乎它也不会使原型链更长......
_.extend(Employee.prototype, Person.prototype);
_.extend(Employee.prototype, {
doSomething: function() {
return "hi ...";
}
});
但 ...
为什么有 2 个 sayHi 和 doSomething 函数?(实际上当我只做 1 扩展时它是一样的)。