I have the following code that includes Spread Syntax in JS
const opposite = function (f) { return (function (...args) { return !f(...args) }) };
can it be converted without using Spread Syntax? It seems that if I do use this, some of the js minification tools fail to parse these lines of codes.
You can by using the arguments object in combination with Function.prototype.apply():
The
argumentsobject exist inside every function call and it represents the arguments to the function. Using this we can capture any and all arguments passed to the function.The
applymethod on the other hand allow you to call a function by passing an array to represent the arguments.Combining both we can do this: