Может ли кто-нибудь сказать мне, почему это не работает?Array.prototype.forEach.call дает TypeError: Незаконный вызов
Array.prototype.forEach.call(document.body.children, console.log);
Я получаю следующее сообщение об ошибке:
Uncaught TypeError: Illegal invocation(…)(anonymous function)
что кажется ерундой, как следующий и работу:
Array.prototype.forEach.call(document.body.children, function() {console.log(arguments)});
Array.prototype.forEach.call(document.body.children, l=>console.log(l));
NOTE: the function being called (
console.log
in this case) is just an example, the original intent was to usedocument.body.removeChild
instead, but this failed in the same way.ANOTHER NOTE: I've only tried this in Chrome. I tried the following in a node.js console and it worked fine:
Array.prototype.forEach.call(myArray, console.log)
'console.log.bind (консоль),' document.body.removeChild.bind (document.body) ' –
Ах так что мне нужно, чтобы связать' документ. body' (или элемент DOM) Я вызываю 'removeChild' on - спасибо @SergeSeredenko – Robin