3 ms·
Question from a backend dev who need to do some JavaScript from time to time. What version should I use? With backend stuff I am usually responsible for insta
by collyw 9y ago
Question from a backend dev who need to do some JavaScript from time to time.
What version should I use?
With backend stuff I am usually responsible for installing the versions of the code / language / libraries that I use. With browsers what can I reasonably expect users to have in their browser?
- nostalgeek 9y ago> What version should I use? With backend stuff I am usually responsible for installing the versions of the code / language / libraries that I use. With browsers what can I reasonably expect users to have in their browser? this is a tricky question. You need to test each feature you want to use on targeted browsers, really. Or use a specialized compiler that will compile your javascript to a former version of the language (a tool like babel does that). A site like https://caniuse.com https://caniuse.com can help you identify which feature works on what browser. But at the end of the day, it's like DOM API, your scripts need to be tested and errors monitored in production.
- collyw 9y agoThanks, that site looks useful.
- yunyu 9y agoJavaScript on the client is usually transpiled and polyfilled to work with older versions with something like Babel. You'd use something like babel-preset-env, which allows you to specify the level of compatibility you're targeting. The default configuration assumes that your clients support ES5.
- davedx 9y agoDepends on your users. For B2B or internal applications it's probably acceptable to say "IE 7 is not supported" and write modern ES6 without transpilation. If it's for a more general audience then using a toolchain like webpack+babel might be safer and more suitable. You'll also need a toolchain for larger apps to be able to use the module system (import statements) for now.
- WorldMaker 9y agoTypescript is great transpiler of the latest version of the language (and some Stage 3 proposals for the next version) to older versions that run in most browsers. It also gives you the option to bring in the benefits of static typing, which makes organizing and managing projects so much better.