1、hasOwnProperty和mixin
然后利用default来实现mixin效果
通过hasOwnProperty来执行排除了prototype中继承的属性的拷贝
代码来自于zrender.js 3.x
function defaults(target, source, overlay) {
for (var key in source) {
if (source.hasOwnProperty(key)
&& (overlay ? source[key] != null : target[key] == null)
) {
target[key] = source[key];
}
}
return target;
}
然后利用default来实现mixin效果
function mixin(target, source, overlay) {
target = 'prototype' in target ? target.prototype : target;
source = 'prototype' in source ? source.prototype : source;
defaults(target, source, overlay);
}