In JavaScript, lazy getters can improve performance.
Some explanation can be found here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#Smart_self-overwriting_lazy_getters
How do I get lazy getters working in strict mode?
This JavaScript code does not work:
'use strict'
function Obj(x) {
this.x = x
}
Obj.prototype = {
get y() {
delete this.y
return this.y = this.x + 1
}
}
let obj = new Obj(100)
console.log('100 + 1 = ', obj.y)
It gives the following error: TypeError: setting getter-only property "y"
If I remove 'use strict', then the code works fine.
How do I get this to work in strict mode?