I implement functional programming from Eloquent Javascript to the JS console in Google Chrome. There is a function that passes through each element in the array and performs this action in the initial parameter for the specified element.
function forEach(array, action) { for (var i = 0; i < array.length; i++) action(array[i]); } forEach(["Wampeter", "Foma", "Granfalloon"], console.log);
I expect the console to print every element in my array, but I get this in red:
TypeError: 'Illegal Invocation'
Is there a way to print this on my js console, or do I need to use something else to compile the code?
source share