How do I pass a function as a parameter without the function executing in the \"parent\" function or using eval()
? (Since I\'ve read that it\'s insecure.)
I suggest to put the parameters in an array, and then split them up using the .apply()
function. So now we can easily pass a function with lots of parameters and execute it in a simple way.
function addContact(parameters, refreshCallback) {
refreshCallback.apply(this, parameters);
}
function refreshContactList(int, int, string) {
alert(int + int);
console.log(string);
}
addContact([1,2,"str"], refreshContactList); //parameters should be putted in an array