Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let Parent = function Parent() {
- console.log('Parent constructor');
- };
- Parent.prototype = {
- constructor: Parent,
- foo: function () {
- console.log('Parent foo');
- },
- super: function() {
- let caller = this.super.caller;
- var parent = this.superclass;
- // Вызов конструктора
- if (this instanceof this.super.caller) {
- parent.apply(this);
- } else {
- if (caller.name && parent.prototype[caller.name]) {
- parent.prototype[caller.name].apply(this);
- }
- }
- }
- };
- Parent.inherit = function (Constr, Prototype) {
- Constr.prototype = Object.create(this.prototype);
- Object.assign(Constr.prototype, Prototype);
- Constr.prototype.constructor = Constr;
- Constr.inherit = this.inherit;
- Constr.prototype.superclass = this;
- return Constr;
- };
- let Child = Parent.inherit(function Child() {
- this.super();
- }, {
- foo: function() {
- this.super();
- }
- });
- (new Child).foo();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement