1 回答
TA贡献1921条经验 获得超9个赞
可以尝试用Prixy来实现,但是需要调用代理后的对象而不是原类
(()=>{
class Test{
static staticMethod(){
console.log(`this is staticMethod`);
}
}
class Test2 extends Test{
static staticMethod2(){
console.log(`this is staticMethod2`);
}
}
var P = new Proxy(Test, {
apply: (target, that, args) => {
console.log("apply", target, that, args);
},
get: (target, property, receiver) => {
if(property in target){
return target[property];
}else{
return Test2.staticMethod2;
}
}
});
P.staticMethod();
P.staticMethod2();
})();
添加回答
举报