2 ms·
The biggest fundamental is that you only rarely need new (when forced upon you by a bad API) and you don't need this (not ever). That statement has worked well
by austincheney 8y ago
The biggest fundamental is that you only rarely need new (when forced upon you by a bad API) and you don't need this (not ever).
That statement has worked well for me in this language. I know it causes many people to cry and get immediately angry. The bottom line is that they increase the verbosity (substantially) of code, they are completely optional, and they often compound code maintenance through a more convoluted flow control.
- Silhouette 8y agoI can understand not liking `this` in JavaScript, but it seems optimistic to say you never need it. If nothing else, you are bound to encounter large amounts of code that uses it, so being familiar with its behaviour is necessary to understand that code.
- DonHopkins 8y ago"... but it seems optimistic to say you never need it. If nothing else, you are bound to encounter large amounts of code that uses it" Wait -- JavaScript now supports "it"??! Can you iterate over "them"? At least it's not gendered, so you need to use "him" and "her" and "it" depending on the object's gender, or just keep everything in a collection so you can use "them".
- josephg 8y agothis also has some really fun rules that are useful for mad science sometimes. For example, you can recover the JS context's global value via this: (function() { return this })() In a browser this resolves to the window object. In nodejs it resolves to the global object. I've used this a few times to help write isomorphic javascript bundles, though its much less useful than it once was.