4 ms·
I used to really feel the same, and tried to make no-js sites for a bit. Long story short, eventually you're going to want some user interaction beyond submitt
by seph-reed 6y ago
I used to really feel the same, and tried to make no-js sites for a bit.
Long story short, eventually you're going to want some user interaction beyond submitting forms, and if you've built your site as anything other than a js SPA, it's quickly going to become ugly.
- kiwidrew 6y agoI wonder, would it be possible to identify a subset of Javascript that is benign? Perhaps some rules about which functions the script is permitted to use, along with restrictions on looping constructs (iterate through an array = OK; unbounded recursion = not OK)... That way simple stuff like: var form = document.forms[0]; document.getElementById('foo').addEventListener('change', function (e) { if (e.target.value == 'xyzzy') form.elements['bar'].classList.add('show'); } ); would be perfectly fine, but crazy "let's exploit the JIT" or "emulate an entire 8-bit home computer" stuff would be rejected. And then, as a bonus, we could dump the entire JIT infrastructure and go back to a simple JS interpreter (a la Duktape) because there just wouldn't be much code left to interpret in the first place.
- bigiain 6y ago> (iterate through an array = OK; unbounded recursion = not OK)... Right, so all we need to do is solve the halting problem... <smirk>
- userbinator 6y agoThe halting problem is about the general case, but when deciding a sane subset of JS, one can always be more conservative.
- saagarjha 6y agoYeah, if your subset of JavaScript is not Turing complete.
- kiwidrew 6y agoYeah, so some syntactic rules (using Array.forEach() instead of for(;;) loops) and prohibiting some of Javascript's more dynamic features might be enough to render the language non-Turing complete. It would also -- and this is kind of the point -- render the language unable to perform certain computations that plain vanilla Javascript can perform.
- anonms-coward 6y agoIf you can prove whether recursion or even a loop is bounded or not, you have solved the collatz conjecture.