lang/js/ ApplyParametersToFunction
From here at mozilla
const numbers = [5, 6, 2, 3, 7];
const max = Math.max.apply(null, numbers);
console.log(max);
// Expected output: 7
const min = Math.min.apply(null, numbers);
console.log(min);
// Expected output: 2
To apply
with new
we need the following ugly hack (from stack overflow):
var createSomething = (function() {
function F(args) {
return Something.apply(this, args);
}
F.prototype = Something.prototype;
return function() {
return new F(arguments);
}
})()
var x = createSomething("a","b","42")
and we could make an uglier, more general, thing by having a factory that takes a Something
and returns the corresponding `createSomething