Adding custom javascript functions to scala-js-example-app from GitHub -


this based on scala-js-example-app github.

i have function want define in javascript , not defined scala.js library.

in copy of scalajsexample.scala file, have:

object mine extends js.object {     def foobarfoo():string = ??? //this simple example , know can done in scala, go it. }  object scalajsexample extends js.jsapp {   def main(): unit = {     val paragraph = dom.document.createelement("p")     paragraph.innerhtml = "<strong>it works!" + mine.foobarfoo() + ".</strong>"     dom.document.getelementbyid("playground").appendchild(paragraph)   }    /** computes square of integer.    *  demonstrates unit testing.    */   def square(x: int): int = x*x } 

now want define foobarfoo in javascipt.

i've tried writing in javascript file:

function foobarfoo() { return "hello, world!"; } 

and didn't work, tried more scala.js syntax:

var mine = {     foobarfoo: function() { return "hello, world!"; } } 

and many other variations, none of these worked , couldn't "hello, world!" appear on webpage after compilation.

how should write foobarfoo() right result?

resuming discussion, problem inclusion order: op added custom javascript functions after scala.js code:

<script type="text/javascript" src="./target/scala-2.11/example-opt.js"></script> <script type="text/javascript" src="./target/scala-2.11/example-launcher.js"></script> <script type="text/javascript" src="src/main/scala/example/myscript.js"></script> 

therefore, requested function couldn't found. putting myscript.js top solved issue:

<script type="text/javascript" src="src/main/scala/example/myscript.js"></script> <script type="text/javascript" src="./target/scala-2.11/example-opt.js"></script> <script type="text/javascript" src="./target/scala-2.11/example-launcher.js"></script> 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -