首页 > 试题广场 >

以下代码的输出是什么?```javascriptconst

[单选题]
以下代码的输出是什么?
const handler = {
apply(target, thisArg, args) {
console.log('apply');
return Reflect.apply(target, thisArg, args) * 2;
},
construct(target, args) {
console.log('construct');
return { value: args[0] * 3 };
}
};
function Foo(x) { return x + 1; }
const ProxiedFoo = new Proxy(Foo, handler);
console.log(ProxiedFoo(5));
console.log(new ProxiedFoo(5).value);
  • apply 12 construct 15
  • apply 6 construct 15
  • 5 construct 15
  • apply 12 construct 5
  • 普通调用 ProxiedFoo(5)→ 触发apply
  • new 调用 new ProxiedFoo(5)→ 触发construct
发表于 2026-03-31 08:14:14 回复(0)