Reputation: 86747
I want to extend Context2d in order to create a specific method that can be invoked by context.myMethod();
Using this class:
class MyContext extends Context2d {
public myMethod();
}
BUT I'm creating the canvas by Canvas canvas = Canvas.createIfSupported();
and thus I would get the Context2d by canvas.getContext2d();
How can I now force the latest method to return MyContext
class which extends the Context2d
, as there is no setContext2d
() on a canvas element...
Upvotes: 0
Views: 139
Reputation: 64541
Context2d
is a JavaScriptObject
so all you need is to cast it to MyContext
and/or use the cast()
method:
MyContext ctx = canvas.getContext2d().cast();
Upvotes: 1