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)执行的时候为何class A中的construct没执行