2
I found an implementation of lists linked in javascript and saw this method that returns the first node that satisfies the callback condition and did not understand very well the first if, I understood that it checks if callback is a function "Object.prototype.toString.call(callback)", does this call a toString method using which callback is associated ? If I’m not mistaken.
Link if necessary to understand the context: Implementing a Linked List in Javascript
find(callback){
if(Object.prototype.toString.call(callback) !== '[object Function]'){
return new TypeError(callback + ' is not a function');
};
if(!this.head) return false;
let currentNode = this.head;
while(currentNode){
if(callback && callback(currentNode.value)) {
return currentNode;
}
currentNode = currentNode.next;
};
return undefined;
}