Skip to content

Commit 5932a1a

Browse files
authored
Merge pull request #557 from japgolly/topic/custom-js-fns
Document creating JS functions with varargs
2 parents 8eaa582 + 9767692 commit 5932a1a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

doc/interoperability/types.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,21 @@ var o = new Object();
273273
var x = f.call(o, 4);
274274
{% endhighlight %}
275275

276+
### JS functions with varargs
277+
278+
In order to capture varargs from a JS function, create your own trait that
279+
extends `js.Function` or `js.ThisFunction`.
280+
281+
{% highlight scala %}
282+
trait JsVarargsFn extends js.Function {
283+
def apply(args: Any*): Unit
284+
}
285+
286+
val f: JsVarargsFn = { args =>
287+
println(s"This method was called with ${args.size} args.")
288+
}
289+
{% endhighlight %}
290+
276291
## Dynamically typed interface: `js.Dynamic`
277292

278293
Because JavaScript is dynamically typed, it is not often practical, sometimes

0 commit comments

Comments
 (0)