var cache = new Proxy(new Map(), {
apply: function(target, thisArg, argumentsList) {
console.log('hello world!');
}
});
cache.set('foo', 'bar');
As far as I can tell this should result in hello world!
being logged to the console and the Map's foo
key not being set. However, when I run this, it throws:
TypeError: Method Map.prototype.set called on incompatible receiver [object Object]
at Proxy.set (native)
at repl:1:7
at ContextifyScript.Script.runInThisContext (vm.js:23:33)
at REPLServer.defaultEval (repl.js:340:29)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.onLine (repl.js:537:10)
at emitOne (events.js:101:20)
at REPLServer.emit (events.js:189:7)
at REPLServer.Interface._onLine (readline.js:238:10)
I've Googled and gone over all the MDN Proxy docs several times, and I can't wrap my head around why this isn't working.
Any ideas? I'm on Node.js 7.5.0.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…