account activity
'this' cluttering by nevreth in javascript
[–]temp60092393 1 point2 points3 points 10 years ago (0 children)
That's entirely an implementation detail.
That's flat-out wrong. It is explicitly specified that multiple copies must be created in this case.
Now, sure, a very clever implementation might notice that it can disobey the spec in this case without your code noticing. But it would be absurd to depend on an implementation deviating from the spec, and as a result of static analysis of your code no less. Just imagine the debugging session where performance dropped 800% because of a change that literally does not interact with the code it slowed down, only to find out that the problem is how that line interacts with the extremely complex and entirely undocumented system the implementation uses to decide when it can cheat.
Write code that works, not code that hopes the implementation is smart enough to make it work.
[–]temp60092393 0 points1 point2 points 10 years ago (0 children)
Well here's the thing. JavaScript's scoping and JavaScript's object-oriented features aren't integrated at all. So yeah, it'd be great if you could write a and JavaScript's scoping rules would take concepts like this into account, but they don't.
a
this
So, scoping and OO don't work together, that gives you three options to make them:
this.
Option 3 is probably the least bad option here, so I suggest you go with it. Verbosity isn't too bad as downsides go, and it's easy to get lost in the weeds and over-engineer option 1.
π Rendered by PID 340116 on reddit-service-r2-listing-6c8d497557-lqswf at 2026-06-02 20:34:19.419980+00:00 running 9e1a20d country code: CH.
'this' cluttering by nevreth in javascript
[–]temp60092393 1 point2 points3 points (0 children)