So I have this function
window.initFloof = function (callback) {
....
let val1 = 22; // Sample value
if (callback !== null) {
if (typeof callback === "function") {
// callback(val1); // Both are working but arguments don't get passed.
window[callback](22); // Both are working but arguments don't get passed.
}
}
}
I am calling the above function as below
window.initFloof('callbacky');
Now the callbacky
function.
window.callbacky= function (val1) {
console.log(val1); // This is giving Undefined, while I am expecting a `22` as per the above example. Alerts if set, are triggering btw which means the function is being executed.
};
EDIT:-
OK guyz, Extremely sorry my bad, I was actually using
if (typeof window[callback]() === "function") {
...this got lost in distilling my function down for posting here. I agree It was my bad, feeling goofy now.
And also I realize where my problem was, In the above line, Instead of checking if the function existed It was actually being executed and since the condition was not being met, the actual line of code window[callback](22);
was just being skipped over, hence the title, argument was not being passed.