-
Book Overview & Buying
-
Table Of Contents
Web Development with Julia and Genie
By :
In certain use cases, you might want to use JS for client-side web programming together with Julia. The client JS code could even be generated by Julia using part or a combination of the JSExpr, Blink, and WebIO packages, as we’ll see in the following sections.
The JSExpr.jl package (https://github.com/JuliaGizmos/JSExpr.jl) translates Julia syntactically into JS. As usual, you can get it in the REPL package mode through add JSExpr, and then a using JSExpr command in the normal REPL.
JSExpr works by providing two dedicated macros: @js and js"".
@js transpiles a Julia expression into JS. It does this by making a JSString, which contains the JS code as a string. The following is an example of converting a Julia cube function into its JS equivalent:
@js function cube(arg) return arg * arg * arg end
The return value is as follows:
JSString("function cube(arg){return (arg*arg*arg)}")
In the following example...