4 ms·
I'd add that it's too easy to pollute the global scope accidentally, because a simple anonymous block structure (e.g. braces) to scope variables is not allowed.
by sixbrx 15y ago
I'd add that it's too easy to pollute the global scope accidentally, because a simple anonymous block structure (e.g. braces) to scope variables is not allowed. Best workaround is to wrap most all code in an anonymous function that is then immediately executed (function() {<your code here}}).(), but that's ugly and easy to forget.
I think Coffeescript does this by default for all blocks of code, which IMO is one of the principal reasons for preferring it to original javascript.
- lowboy 15y ago> which IMO is one of the principal reasons for preferring it to original javascript. It's a nice feature, but saying it's one of the principle reasons to prefer CS over JS is a stretch. Wrapping your entire file in an IIFE is a one-time development cost and a simple pattern to remember. Compare that to the syntactic sugar, safeguards, and added functionality that one will leverage constantly during development.