I don't see how syntactic sugar makes any sense for javascript. Breaking compatibility is so severe because every browser needs to catch up, yet it doesn't actually enable anything that couldn't be done before.
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.
Pipe Operator (|>) For JavaScript
11–20 of 437 posts
Re: Pipe Operator (|>) For JavaScript
#12I don't see how syntactic sugar makes any sense for javascript. Breaking compatibility is so severe because every browser needs to catch up, yet it doesn't actually enable anything that couldn't be done before.
Re: Pipe Operator (|>) For JavaScript
#13I love the pipe operator in Elixir!
The current JS one isn't as nice as the Elixir one, at least it wasn't when I tried using it via Babel a couple yrs ago.
computation() |> &(Map.put(my_map, key, &1)).()
That said, with this less-power, you do kind of end up forced to design your functions in a way to where piping makes sense, and IMO it leads to cleaner and more consistent APIs.Re: Pipe Operator (|>) For JavaScript
#14They should have stuck with the F# proposal. The hack proposal just takes one more giant step toward turning JS into Perl. Hack proposal value |> foo(%) for unary function calls, value |> foo(1, %) for n-ary function calls, value |> %.foo() for method calls, value |> % + 1 for arithmetic, value |> [%, 0] for array literals, value |> {foo: %} for object literals, value |> `${%}` for template literals, value |> new Foo…
Re: Pipe Operator (|>) For JavaScript
#15Earlier quoted context omitted.
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.
If you're compiling to javascript anyway, why would you need a pipe operator in javascript instead of just nesting the function calls?
Re: Pipe Operator (|>) For JavaScript
#16Earlier quoted context omitted.
If you're compiling to javascript anyway, why would you need a pipe operator in javascript instead of just nesting the function calls?
Because x |> f |> g |> h is much easier to read than h(g(f(x))) for most people.
Re: Pipe Operator (|>) For JavaScript
#17I don't see how syntactic sugar makes any sense for javascript. Breaking compatibility is so severe because every browser needs to catch up, yet it doesn't actually enable anything that couldn't be done before.
Firefox usage is down to a rounding error, and they happily implement whatever the commercial duo decides the web should have.
Re: Pipe Operator (|>) For JavaScript
#18I'm pretty sure this'd be a welcome addition to the language but to be honest, the syntax looks shit.
Re: Pipe Operator (|>) For JavaScript
#19I don't see how syntactic sugar makes any sense for javascript. Breaking compatibility is so severe because every browser needs to catch up, yet it doesn't actually enable anything that couldn't be done before.