I am attempting to use a javascript class in GWT. Here is the sample code I
am using.
Javascript file - rhombus.js
class Rhombus {
static isReady() {
return true;
}
}
Java file - Rhombus.java
package com.xyz.graphics;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;
@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public class Rhombus {
public static native boolean isReady();
}
index.html
<script src="js/rhombus.js"></script>
<script src="app/app.nocache.js"></script>
When I try to access Rhombus.isReady(), I get
(TypeError) : Cannot read properties of undefined (reading 'isReady')
However I can access the method correctly if I attach Rhombus to the window
object.
<script type="text/javascript">
window.Rhombus = Rhombus;
</script>
I don't understand why attaching the class to the window object is
necessary, as none of the documentation makes a mention of that.
--
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 on the web visit
https://groups.google.com/d/msgid/google-web-toolkit/a891b58c-fd75-43a7-ae4b-6cef06ba0193n%40googlegroups.com.