I've searched the site for this question and got the following answer:
function instance_of(V, F) {
var O = F.prototype;
V = V.__proto__;
while (true) {
if (V === null)
return false;
if (O === V)
return true;
V = V.__proto__;
}
}
It's from https://stackoverflow.com/a/9220317/12974414.
But I tested the following code, found something weird:
console.log( (10).__proto__ === Number.prototype ) // true
console.log( instance_of(10, Number ) ) // true
console.log( 10 instanceof Number ) // false
function instance_of(V, F) {
var O = F.prototype;
V = V.__proto__;
while (true) {
if (V === null)
return false;
if (O === V)
return true;
V = V.__proto__;
}
}
How to explain this and how does instanceof operator actually work in JS ?