在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/PHP  HTML/ nodejs 如何實(shí)現(xiàn) php 的 __callStatic 魔術(shù)方法 ?

nodejs 如何實(shí)現(xiàn) php 的 __callStatic 魔術(shù)方法 ?

nodejs 如何實(shí)現(xiàn) php 的 __callStatic 魔術(shù)方法 ?
或者說(shuō), 如何 如何使用 nodejs 實(shí)現(xiàn) static 對(duì) 普通方法的呼叫 ?

回答
編輯回答
笑浮塵

可以嘗試用Prixy來(lái)實(shí)現(xiàn),但是需要調(diào)用代理后的對(duì)象而不是原類

(()=>{
    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();
})();
2018年9月8日 10:23