Created
April 30, 2015 06:55
-
-
Save kitelife/960c6982b4afde23a2b0 to your computer and use it in GitHub Desktop.
简单地通过将父对象的属性拷贝给子对象来构建继承
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function extend(Child, Parent) { | |
var p = Parent.prototype; | |
var c = Child.prototype; | |
for (var i in p) { | |
c[i] = p[i]; | |
} | |
c.uber = p; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这种方式仅适用于只包含基本数据类型的对象,所有的对象类型(包括函数与数组)都是不可复制的,因为它们只支持引用传递