I agree with and appreciate nearly all of these suggestions. Just a few well-intentioned quibbles:<p>> Arrays MUST be created using the Array syntax literal.<p>This does enhance readability when vending an empty array, but when you know how large an array will need to be in advance, new Array(someLength) is an important pattern. Consider this naïve implementation of Clojure's "reductions" or Haskell's "scanl":<p><pre><code> let reductions = (callback, initial, array) =>
array.reduce( (memo, element) => {
memo.push( callback(memo[memo.length - 1], element) );
return memo;
}, [initial]);
</code></pre>
This will call push() array.length times. If the backing store for Array is a typical vector implementation that reallocates every time its length exceeds a power of 2, this means incurring log₂(array.length) reallocations, and suffering the concomitant heap fragmentation. However, if we pre-allocate an array of the appropriate size once before entering the loop,<p><pre><code> let reductions = (callback, initial, array) => {
let result = new Array(array.length + 1);
result[0] = initial;
array.forEach( (element, index) =>
result[index + 1] = callback(result[index], element)
);
return result;
};
</code></pre>
we can avoid creating unnecessary work for the VM.<p>> Regular (named and hoisted) function declarations SHOULD be used instead of anonymous functions by default.<p>I think this is really bad advice. Hoisting makes imperative code harder to reason about; any time that it would actually make a difference, the un-hoisted behavior is the one I would want. The verbosity of let myFunction = function(x,y) {}; over myFunction(x,y) {} is definitely unsightly, but it's worth my peace of mind.<p>> undefined MUST NOT be used, void 0 MUST be used instead. [...] Pure convention. Also void 0 looks more l33t.<p>undefined should be preferred on grounds of readability. If ES3 compatibility is really important, you can configure babel to emit void 0 in place of undefined with the spec.undefinedToVoid optional transformer.
Really nice (and a fantastic JavaScript overview in general), though the MUST and SHOULD's get a bit wearing on the eyes after some time; perhaps a simple <i></i>bold<i></i> would suffice?