__defineGetter__() and __defineSetter__() can no longer be called at the global scope

Published: | Categories: JavaScript


Previously, the __defineGetter__ and __defineSetter__ methods could be called at the global scope without any object, because the global object was automatically used in such cases. As part of the ECMAScript 2016 (ES7) compliance, Firefox 48 and later no longer support the legacy behaviour and throw a TypeError instead. The workaround here is to explicitly use the this keyword, like this.__defineGetter__ or this.__defineSetter__.