Using spread syntax with function Arguments object
You can also use rest parameters:
function Numbers(...numbers){
this.numbers = numbers;
}
Using a spread does the same thing cleaner in ES2015
this.numbers = [...arguments];
Just remember that this won't work in arrow functions (no arguments
), and you're good. Rest arguments and Array.from are other options that are fine as well.
The old-fashioned ES5 is:
this.numbers = [].slice.call(arguments);