class A { construct(name) { console.log('name: ', name); console.log('this: ', this) this.name = name; } testFunction() { console.log('testFunction') }}const singletonify = (OriginalClass) => { let i return new Proxy(OriginalClass, { construct (target, args) { console.log('test') console.log(args) if (!i) i = Reflect.construct(target, args); return i } })}singleA = singletonify(A)a = new singleA()Reflect.construct(target, args)執(zhí)行的時候為何class A中的construct沒執(zhí)行
Proxy和Reflect實現(xiàn)單例模式
元芳怎么了
2019-03-04 16:27:41