3 ms·
I want to take this further still. Most JavaScript programmers already use a subset of the language and I believe that there is quite a broad union of those sub
by olov 15y ago
I want to take this further still. Most JavaScript programmers already use a subset of the language and I believe that there is quite a broad union of those subsets that should resonate with the majority of us. Excluding certain parts of the language will lead to more robust code that is easier to reason about (and more fun to write), I claim. My attempt to formalize it is called "restrict mode for JavaScript" http://restrictmode.org http://restrictmode.org and I laid my case here: http://blog.lassus.se/2011/03/case-for-restrict-mode.html http://blog.lassus.se/2011/03/case-for-restrict-mode.html . Would be curious to hear other thoughts about it.
- tikhonj 15y agoI think Resig means to use JSLint throughout, which does something similar. Additionally, browsers already support "use strict" which is also a restricted mode. In short, plenty of people share your views on the matter (me included). The whole thesis of JavaScript: The Good Parts was basically that, and the book is one of the best on the language.
- olov 15y agoThe major difference is that JSLint as well as "the good parts" focus on a subset that can be verified statically (before running the program) while restrict mode sanitizes operator semantics that must be verified dynamically (when running the program). I like the few changes strict mode did except for one thing that breaks compatibility in an unfortunate way (this is bound to the primitive, not the boxed number). But we should take all this much further. More important than anything I'd like us to start talking about sane subsets of JS more, and stop limiting ourselves to what one author considers "good" because quite frankly, _that_ subsets still contains a whole lot of awful stuff.