I can not solve this case - linter points me to other solution. This is my original code:
if (arguments[0] && typeof arguments[0] === 'object') {
this.options = extendDefaultProperties(defaultProperties, arguments[0]);
}
Any help? Thank you in advance.
Rest parameters represent the unknown number of arguments inside the function, whereas the arguments object represents all arguments passed to the function. Rest parameters are pure array, whereas the arguments object is not a real array.
The rest parameter syntax allows a function to accept an indefinite number of arguments as an array, providing a way to represent variadic functions in JavaScript.
The rest parameter and arguments object are different from each other. Let's see the difference between the rest parameter and the arguments object: The arguments object is an array-like (but not array), while the rest parameters are array instances.
A rest parameter allows us to pass zero or any number of arguments of the specified type to a function. In the function definition where we specify function parameters rest parameters should always come at last or the typescript compiler will raise errors.
Use the rest parameters to collect the params into the array args
:
demo(...args) {
if (typeof args[0] === 'object' && args[0] !== null) {
this.options = extendDefaultProperties(defaultProperties, args[0]);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With