Skip to content

Instantly share code, notes, and snippets.

@roshanca
Created March 11, 2020 12:19
Show Gist options
  • Save roshanca/61e48025b551d4745e1f2d76d814ddf8 to your computer and use it in GitHub Desktop.
Save roshanca/61e48025b551d4745e1f2d76d814ddf8 to your computer and use it in GitHub Desktop.
JS 继承 #js #prototype
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