Warum ist ein „canvas“-Element keine „instanceof HTMLCanvasElement“?JavaScript

Javascript-Forum
Guest
 Warum ist ein „canvas“-Element keine „instanceof HTMLCanvasElement“?

Post by Guest »

Ich versuche, die toDataURL-Methode für HTMLCanvasElement zu überschreiben, aber zur Laufzeit meldet sich das Element, das ich beeinflussen möchte, nicht als Instanz von HTMLCanvasElement. Warum sollte das so sein?
Image
Wenn ich document.createElement('canvas').toDataURL() aufrufe, rufe ich die überschriebene Methode erfolgreich auf.

Code: Select all

// Tried both methods of overriding, but obviously the real question is about the `instanceof` values in the image above.

HTMLCanvasElement.prototype.toDataURL = new Proxy(HTMLCanvasElement.prototype.toDataURL, {
apply(target, self, args) {
return Reflect.apply(target, self, args);
},
});

// and...

HTMLCanvasElement.prototype.toDataURL = () => {
// do stuff here
};

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post