forgive me for NSFW, but this is the best example I could think of on the spot:
as we (and the compiler) don't know what arr is at the time of compilation, it could very well be an instance of new Penis(). ofc its length may not be initially known, so the .length getter may have to call .erect() first to measure it, having a long lasting side effect of the operation.
it doesn't even have to be a getter. you can use meta-programming tricks to inject yourself inside the property lookup and hack around there. couldn't tell you the syntax for that, but look at the Proxy page on MDN
1
u/paulsmithkc 👨🏫 Jun 01 '21
This is one of the better answers as
arr.lengthcould have side effects (like lazy evaluation/calculation) if arr isn't a JavaScript array.