Using Kotlin/js, here's something that works:
fun main() {
val canvas=document.getElementById("mainCanvas") as HTMLCanvasElement
val ctx=canvas.getContext("2d") as CanvasRenderingContext2D
val path=Path2D()
path.rect(10.0,10.0,10.0,10.0)
ctx.stroke(path)
}
Here's something that doesn't work:
fun main() {
val canvas=document.getElementById("mainCanvas") as HTMLCanvasElement
val ctx=canvas.getContext("2d") as CanvasRenderingContext2D
val path=ExtraPath()
path.rect(10.0,10.0,10.0,10.0)
ctx.stroke(path)
}
class ExtraPath():Path2D(){
fun extraFunction(){}
}
When it runs in the client, js complains that Path2D constructor: 'new' is required.
So what's the correct way to extend one of these js wrapper classes?