I am trying to modify some functionality of the canvas context object without having to alter any code that is using this.
A solution for this by creating a Proxy
object has been posted here: JS Proxying HTML5 canvas context.
My question is: Can this behaviour be achieved without relying on Proxy
by using ctx
as a prototype?
Directly using it like this
let acx = Object.create(ctx, {})
acx.fillStyle = 'red'
results in the same Error messages as mentioned in the linked question
TypeError: 'set fillStyle' called on an object that
does not implement interface CanvasRenderingContext2D.
on all ctx methods I've tested.
In the linked question this is explained as CanvasRenderingContext2DPrototype
not accepting the fake ctx object. What exactly does accepting mean here? Is there any way to fix this?