I'm implementing functional programming from Eloquent Javascript to my JS console in Google Chrome. There's a function that loops through each element in an array and performs the given action in the initial parameter to said element.
function forEach(array, action) {
for (var i = 0; i < array.length; i++)
action(array[i]);
}
forEach(["Wampeter", "Foma", "Granfalloon"], console.log);
I am expecting the console to print out each item in my array, but I get this in red:
TypeError: 'Illegal Invocation'
Is there a way I can print this on my js console or should I use something else to compile the code?