In clojureScript the following multi-arity function
(defn sum [& xs] (reduce + xs))
can be either called via (sum 4 6 9)
or by the use of (apply sum [4 6 9])
which yields the same result.
How can this be done with a native JavaScript function, such as: console.log
.
(apply js/console.log [1 2 3])
This, yields the following error:
#object[TypeError TypeError: 'log' called on an object that does not implement interface Console.]
console.log.apply(console, […])
to make it work (though it's browser-specific) – Minstrel(apply js/console.log [1 2 3])
and(js/console.log 1 2 3)
both print1
and returnnil
– Alert(apply js/console.log [1 2 3])
to the browser from the figwheel repl; it logged1 2 3
--- I'm using a current version of Chrome, what are you using? – Alert(apply js/Math.sqrt [25])
? It should return 5 without a problem. – Alert