Henry-Diasa / awesome_interview_question

总结前端面试题,更贴近于实战,而非背诵的八股文。
11 stars 0 forks source link

class实现 #485

Open Henry-Diasa opened 1 year ago

Henry-Diasa commented 1 year ago

寄生组合式继承 + setPrototypeOf实现静态属性的继承

   function selfClass(Child, Parent) {
         Child.prototype = Object.create(Parent.prototype, {
               constructor: {
                    enumerable: false,
                    configurable: false,
                    writable: true,
                    value: Child
                }
         })
         Object.setPrototypeOf(Child, Parent);
   }