我有一个实现继承的函数:
function extend(original, extension) {
for (var key in extension) {
if (extension.hasOwnProperty(key)) {
original[key] = extension[key];
}
}
};
我有两个小物件:
var a={/* created dynamically */}
var b={/* created dynamically */}
然后我可以做:
extend(a, b) //if a is original & b is extension
或
extend(b, a) // if b is original & a is extension