Because it is only a dictionary (= a plain JS object)

https://registry.khronos.org/webgl/specs/latest/1.0/#5.2

In JS you simply do:

var canvas = document.getElementById('canvas');
var context = canvas.getContext('webgl', { antialias: false, stencil: true 
}); // 2nd argument is WebGLContextAttributes
var attributes = context.getContextAttributes();

Looks like it is again defined badly in closure-compiler externs. The 
generated elemental2 implementation should have a similar structure than 
for example elemental2 AddEventListenerOption. It is an interface with a 
static create() method which does exactly what you do in your solution.

See:

https://github.com/google/closure-compiler/blob/dc7f38bb0528b011984ef33a448c7941cf7e0b88/externs/browser/webgl.js#L2918

I think it should be @interface or @record instead of @constructor.


-- J.

Craig Mitchell schrieb am Montag, 28. Juli 2025 um 07:39:57 UTC+2:

> I'm switching to use Elemental2, and it's fantastic.  All the bindings 
> I'll ever need.  A big thank you to all that created it!
>
> There are some strange things though.  Like when setting up a 
> WebGLRenderingContext, we need to pass WebGLContextAttributes.
>
> However, doing:
> WebGLContextAttributes contextAttributes = new WebGLContextAttributes();
>
> compiles fine, but at runtime throws:
> TypeError: $wnd.WebGLContextAttributes is not a constructor
>
> I figured out I can do this instead:
> WebGLContextAttributes contextAttributes = Js.uncheckedCast(JsPropertyMap.
> of());
>
> But why can't I just use its constructor?  Am I doing something wrong?
>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/google-web-toolkit/c0e8f0e3-aeb8-45e6-838f-4e56ab5fb3abn%40googlegroups.com.

Reply via email to