继承而不知道原始和扩展

时间:2014-06-04 21:44:49

标签: javascript inheritance abstraction

我有一个实现继承的函数:

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

0 个答案:

没有答案