It's easy for JS education to descend into shock and awe on how the language can be subverted or is unintuitive. The phrase "You don't know JS" is easy to deploy.
To demonstrate, here's another object you could pass into the protected sum() function to force it to be impure despite the checks...
var x = [0];
Object.defineProperty(x, 1, { get: ()=>x[0]++ });
sum(x); // 1
sum(x); // 5
2
u/robpalme Aug 27 '16
It's easy for JS education to descend into shock and awe on how the language can be subverted or is unintuitive. The phrase "You don't know JS" is easy to deploy.
To demonstrate, here's another object you could pass into the protected sum() function to force it to be impure despite the checks...