I think this is what you want, although it doesn’t make much sense because it will print the first one and it won’t do anything else.
As the error stated, it was missing to declare the arguments
and say that he would be a array of arguments and not just one of them, so I used the ...
which is a construction for this very.
const teste = (...args) => { for(i in args) return args[i]; }
console.log(teste('teste', 123));
I put in the Github for future reference.
Maybe he wanted to use the yield
, but then you can’t use the syntax of Arrow Function?
I changed the variable name according to the bfavaretto comment. He is right that when it comes to the ecosystem of the JS it is possible that some conflict occurs if not today, some day, since arguments
is "magical".
And according to the comment of the AP can not do without stating because he wants a semantics different from what exists "magically" with the use of arguments
. Leave the created convention, you need the configuration that is always more verbose.
The thing was not to pass the (...Arguments) even, as it was a normal function. But I saw that the Arrow functions did not create this.
– Lucas de Carvalho
Thank you, Maniero!
– Lucas de Carvalho
I think it would be more prudent to use
...args
instead ofarguments
. It’s not a reserved word, but I imagine it can be a problem in some cases. Maybe if you transpired into ES5, if the transpilator doesn’t take certain care.– bfavaretto
@bfavaretto indeed, changed.
– Maniero