I have a class Foo
with a static method that compares this
to Foo
, and for some reason the output of that comparison is false
:
// ==UserScript==
// @name GreaseMonkey test
// @version 1
// @grant none
// @include *
// ==/UserScript==
window['Cls'] = class {};
window['func'] = function() {};
console.log(Cls === Cls); // output: false
console.log(func === func); // output: false
How can this be? I suspect it's related to the fact that Greasemonkey executes userscripts in a sandbox with elevated privileges, but even then I cannot understand why this would output false
. Furthermore, the output changes to true
if the function and the class aren't assigned to window
:
class Cls {};
function func() {};
console.log(Cls === Cls); // output: true
console.log(func === func); // output: true
What is going on here?