Skip to content

Instantly share code, notes, and snippets.

@kitelife
Created April 30, 2015 06:55
Show Gist options
  • Save kitelife/960c6982b4afde23a2b0 to your computer and use it in GitHub Desktop.
Save kitelife/960c6982b4afde23a2b0 to your computer and use it in GitHub Desktop.
简单地通过将父对象的属性拷贝给子对象来构建继承
function extend(Child, Parent) {
var p = Parent.prototype;
var c = Child.prototype;
for (var i in p) {
c[i] = p[i];
}
c.uber = p;
}
@kitelife
Copy link
Author

这种方式仅适用于只包含基本数据类型的对象,所有的对象类型(包括函数与数组)都是不可复制的,因为它们只支持引用传递

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment