1

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?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.