scala.js - How to get arguments object in scalajs -


in js, can access function arguments through arguments object.

i want same thing somehow in scalajs, because want logging functions , parameters got.

is possible?

as @justin-du-coeur suggested, can use sourcecode this. example:

object test extends js.jsapp {   def main(): unit = {     a(1, "a")     b()     c("foo", "bar", "baz")   }    def trace()(implicit name: sourcecode.name, args: sourcecode.args): unit = {     def makearglist(as: seq[sourcecode.text[_]]): string =       as.map(a => f"${a.source} = ${a.value}").mkstring("(", ", ", ")")      val argstr = args.value.map(makearglist).mkstring("")     println(f"${name.value}$argstr")   }    def a(arg1: int, arg2: string): unit = {     trace()   }    def b(): unit = {     trace()   }    def c(x: string*): unit = {     trace()   } } 

the output follows:

[info] running test a(arg1 = 1, arg2 = a) b() c(x = wrappedarray(foo, bar, baz)) 

as can see, trace can capture needs context, result more boilerplate free js solution can think of.


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -