Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Comments on Function.prototype.call()
Post
Function.prototype.call()
I wanted to print to browser console the number of li
list items of a given ul
list.
This didn't work (console output was undefined):
console.log(document.querySelectorAll(".example").length);
This worked (console output was a plausible number):
[].filter.call(
document.getElementsByClassName('example')[0].children,
function (el) {
return el.nodeName === 'LI';
}
).length
My question
It was written in the MDN page for Function.prototype.call():
The call() method calls a function with a given this value and arguments provided individually.
But in the working code there was no "this".
What is the meaning of "call" in the second code?
1 comment thread