Created
March 11, 2020 12:19
-
-
Save roshanca/61e48025b551d4745e1f2d76d814ddf8 to your computer and use it in GitHub Desktop.
JS 继承 #js #prototype
This file contains hidden or 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 object(o) { | |
const F = function() {}; | |
F.prototype = o; | |
return new F(); | |
} | |
function extend(Child, Parent) { | |
var prototype = object(Parent.prototype); | |
prototype.constructor = Child; | |
Child.prototype = prototype; | |
} | |
function extend(Parent, Child) { | |
Child.prototype.__proto__ = Parent.prototype; | |
} | |
function extend(Child, Parent) { | |
let prototypeObj = Object.create(Parent.prototype); | |
prototypeObj.constructor = Child; | |
Child.prototype = prototypeObj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment