Can I use GWT (or Script #) to write individual functions in Java (or C #) and compile them into JavaScript?

I understand the purpose of GWT, but I wonder if I can use it to compile several functions from Java to JavaScript, to make sure that I do not need to support the same code in two different languages.

Or will GWT bring too many library support / support resources to make this a smart choice?

For future projects, I have the same question about Script # (C # compiler).


Followup:

Script # seems to create very readable JavaScript from C # (pages 35-51 have examples of C # code and generated JS code).

I found out that there is a flag -STYLEto make the GWT output โ€œbeautifulโ€ or even โ€œverboseโ€. I still don't know if the emitted JS relies on large libraries or if there are other "gotchas".

+3
source share
3 answers

Yes you can do it. Here you can call it from Javascript ( Source ):

How can I call one of my Java GWT methods from my application home page?

, JSNI, JavaScript, , Java . GWT onModuleLoad(), JSNI, JavaScript . - , JavaScript.

? .

( Hanson):

private native void initPlaylistJS  (PlaylistTable pl) /*-{   
   $wnd.addClipToPlaylist = function (clipId, clipTitle) {
        pl.@com.foo.bar.client.PlaylistTable::addClip(Ljava/lang/String;Ljava/lang/String;)(clipId, clipTitle);
    };
}-*/;

initPlaylistJS (pl) GWT onModuleLoad(). GWT , JavaScript GWT .

"", GWT , - .


, , , GWT , GWT, , emulated JRE , .

+2

GWT Java-to-JavaScript, JRE - (, , GWT). "" , JavaScript. , , , , JavaScript, GWT . Java-, GWT, JavaScript . GWT , - ( API- ).

0

, javascript, - Rhino Javascript JVM ?

0
source

Source: https://habr.com/ru/post/1712695/


All Articles