This happens in non strict mode, where compatibility requires that this
is always an object, not a primitive. So in your case this
is an instance of the Number
constructor, and of course that object does not occur in your list.
In strict mode your code works, as this
will be the primitive value (number)
Number.prototype.inList = function (list) {
"use strict";
return list.includes(this);
}
let value = 0;
let find1 = value.inList([0,1]);
let find2 = [0,1].includes(value);
console.log("find1", find1); // true
console.log("find2", find2); // true
Here the strict mode is only effective on the function -- and this is enough for this issue. If your script has no "legacy dependencies", you should better set it globally.