[Starting a new thread, just in case.]
>> I made a list of the 10 biggest JS pitfalls and most of them will be gone
>> under ES6. Much less to worry about, much easier to learn.
>
> Could you share your 10-biggest list?
1. Both undefined and null [not too much of a problem, easily learned]
2. Truthy and falsy values [not pretty, but I’ve grown used to them and the
convenient but sloppy “has a value” checks via `if`]
3. == [easy fix: always use ===]
4. Parameter handling [fixed in ES6]
5. Array-like objects [not completely fixed (DOM...), but `arguments` becomes
obsolete in ES6]
6. Function-scoped variables [`let` FTW in ES6]
7. Accidental sharing of data [for-of will help in ES6]
8. Creating sub-constructors is messy [fixed via classes and `super` in ES6]
9. `this` in non-method functions:
9a) Referring to the `this` of a surrounding method,
9b) accidentally creating globals by forgetting `new`,
9c) using methods as callback functions
[(a) and (b) fixed by ES6 arrow functions and ES5 strict mode]
10. The for-in loop [simple rule: avoid if you can, already possible in ES5]
Thus: 1-3 won’t go away soon. 4-10 are mostly eliminated by ES6.
Deliberate omissions:
- Implicit conversions are messy (and a superset of pitfall #2), but seem to
surprise people much less than the above items.
- Modules close another important hole in JavaScript, but I wouldn’t consider
that hole a pitfall.
There are more pitfalls, but these seemed the biggest ones.
--
Dr. Axel Rauschmayer
[email protected]
home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss