You can annotate the apply method in your facade type with @JSName("apply") . This will give the desired behavior:
trait Test extends js.Object { def apple(idx: Int) : Int = ??? @JSName("apply") def apply(idx: Int) : Int = ??? }
Testing:
val test = js.Dynamic.literal( apply = (idx: Int) => idx, apple = (idx: Int) => idx ).asInstanceOf[Test] test.apple(1) // -> 1 test.apply(1) // -> 1
For a dynamically typed case, you have to manually call applyDynamicNamed :
val dyn = test.asInstanceOf[js.Dynamic] dyn.applyDynamicNamed("apply")(1)
source share