I created an object and put the function in it, then used the bind method to give the function some parameters, but it is undefined in the console.
let numObj = {
multyAll(...args) {
for (let i = 0; i < args.length; i++) {
if (typeof args === Number) {
arguments *= arguments[i]
return arguments
}
}
}
}
const result = numObj.multyAll.bind(1, 2, 3)
console.log(result());
I tried another way around but still, I don't know why I think the function ignores for loop and returns the value of mul which I gave in the beginning
let numObj = {
multyAll(...args) {
let mul = 1
for (arg of args) {
if (typeof arg === Number) {
mul *= arg
}
return mul
}
console.log(mul);
}
}
const result = numObj.multyAll.bind(1, 2, 3)
console.log(result());