4 ms·
It lets a transpiler like Babel or Typescript use the new syntax and output the equivalent code that works on older browser. Same reason async/await was useful
by fnimick 4y ago
It lets a transpiler like Babel or Typescript use the new syntax and output the equivalent code that works on older browser.
Same reason async/await was useful far before there was native browser support - you could immediately use it in your codebase and compile to a legacy browser target.
- CyberDildonics 4y agoIf you're compiling to javascript anyway, why would you need a pipe operator in javascript instead of just nesting the function calls?
- hajile 4y agoBecause x |> f |> g |> h is much easier to read than h(g(f(x))) for most people.
- CyberDildonics 4y agoIf you're compiling from another language you would be using whatever syntactic sugar you want, why break compatibility just to have the compiled javascript look a little better?
- nosianu 4y ago> If you're compiling from another language TypeScript isn't another language though. It is the latest official ECMAScript plus type annotations. Only some very, very few, rare, old stuff like enums really is different code. 99% of TypeScript is just "remove the types to get ECMAScript". That TypeScript, the tool,also adds a transpiler is a distraction that made a lot of people believe TS is a different language. But the TS folks have always taken great pain to only ever support features that are or are about to be in the ECMAScript standard, and not to deviate from it. That they did initially with some namespace stuff and enums was before ES2015, when JS was lacking some things many people thought were essential. Even then they only added less than a handful of "TypeScript-code". When you look at the Babel "transpiler" for Typescript, before they added a bit more for class stuff, it pretty much showed that "transpilation" of TS to JS - as long as you targeted a recent ES version - was achieved by doing nothing more than to remove all those type annotations. I'm still mad at the TS guiys for muddying the waters so much by confusing soooo many people by bundling type checking and transpilation in one tool. This could have been much more clear. I too stuck to using Flow for quite some time until I realized TypeScript really is Javascript, while Flow communicated in its architecture and usage already that it just "added types" (literally).
- CyberDildonics 4y agoYou're completely missing the point here. If you are transpiling something, you don't need to worry about syntactic sugar in the base language you are transpiling to, only what you're transpiling from.
- Rumudiez 4y agoNo, you don’t get it. Babel is for transpiling newer versions of JS to older ones, typically based on targeted browsers or Node runtimes. JS is a fantastic fp language and pipe/compose is commonplace for people writing in that style already. This just adds first class support to the language
- yakshaving_jgt 4y ago> No, you don’t get it. Babel is for transpiling newer versions of JS to older ones For all intents and purposes, JavaScript with all the extra features it has accreted over the years is a different language from the JavaScript of a decade ago, and a compilation step is necessary in order for web browsers to parse it. If you're running a compilation step anyway, you may as well write the code in a language that isn't such a dumpster fire. > JS is a fantastic fp language Actually, it's pretty terrible at that.
- CyberDildonics 4y ago> This just adds first class support to the language If it was a different language you could say it "just" adds something, but javascript is not compiled and any syntax change means you start over as far as compatibility goes. It is unique in its scope and usage and this feature doesn't enable anything new for users and is only marginally useful for programmers.
- Rumudiez 4y agoBrowsers add support for new JS features every year. You can use them or not, I don’t care what you do. Every web stack I’ve worked on in the last 7 years has a compile step, too, so you’re either ignorant or being intentionally obtuse. Either way it’s not like anyone should listen to you. So what’s your point, other than communicating how upset you are over a programming language? That we should be writing websites like it’s 1999?
- deleted 4y ago[deleted]
- icholy 4y agoI just don't want to use source maps anymore ...