How can I call a function named apply()
defined on a Javascript object from Scala.js code?
The obvious solution does not work since apply
is always compiled into a function call on its parent object by Scala.JS (?):
var test = {
apply: function(idx) {...},
apple: function(idx) {...}
}
trait Test extends js.Object {
def apple(idx: Int) : Int = ???
def apply(idx: Int) : Int = ???
}
val test = js.Dynamic.global.test.asInstanceOf[Test]
test.apple(1) // works, of course
test.apply(1) // does not work (seems to be compiled into the call test(1) ?)
js.Dynamic.global.test.apply(1) // does not work either