一、单混入(单继承)
function extend(sourceObj, targetObj) {
for (var key in targetObj) {
if (targetObj.hasOwnProperty(key)) {
sourceObj[key] = targetObj[key];
}
}
return sourceObj;
}
二、多继承
function mix() {
var target = arguments[0];
for (var i = 1, len = arguments.length; i < len; i++) {
var arg = arguments[i];
for (var key in arg) {
if (arg.hasOwnProperty(key)) {
target[key] = arg[key];
}
}
}
return target;
}