I am trying to make a Proxy object Image to catch properties, but even with an empty handler I get an error message.
TypeError: argument 1 of Node.appendChild does not implement the Node interface.
The proxy object should act as the target, so this puzzles me a bit. As far as I understand, you should do this using DOM nodes (?).
Also : I cannot start loading the image and start the onload handler when setting the src property.
How to use a proxy server so that I can "take over", for example, the "src" property, and otherwise it will act like a regular image object?
My code
Update : thanks @Harangue! using " new " (bang ..) certainly launched a proxy object, but Now I can not capture the property setting. It seems to completely ignore the trap - example:
var proxy = new Proxy(Image, { set: function(a,b,c,d){ console.log('set '+b);
How can I catch a property parameter using a valid proxy?
Update 2 On the other hand, using new with a new proxy seems to use the original constructor. All the examples I can find do not use new:
var myProxy = new Proxy(.., ..);
Using then on top of this new myProxy() seems only to use the original constructor, which is not what I want, as it ignores traps.
var proxy = new Proxy(Image, {});
The traps seem to work in my first attempts, but the proxy does not behave as expected. It is so confusing and so new. Rejoice over any contribution, how both can be resolved (traps and behavior).
javascript javascript-objects ecmascript-6 es6-proxy
bjanes
source share