const A = cls => class extends cls { //函数A返回一个继承自cls的子类
constructor (...arges){
console.log('A')
super(...arges);
if (typeof (this.stri) !=='function'){ //判断子类是否有stri方法
throw TypeError('you need to create stri!');
}
}
}
class S {
constructor (x,y) {
this.x = x
this.y = y
}
show () {
console.log(this.x, this.y)
}
}
class S1 extends A(S) {
constructor (...arges) {
super(...arges);
console.log(arges)
}
stri () {
console.log('666')
}
}
a = new S1(1,2)
console.log(a)
js的MiXin技术
最新推荐文章于 2023-02-21 20:18:49 发布