Live data from Hacker News

Pipe Operator (|>) For JavaScript

github.com

1–10 of 437 posts

Re: Pipe Operator (|>) For JavaScript

#3
They 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(%) for constructing objects,
    value |> await % for awaiting promises,
    value |> (yield %) for yielding generator values,
    value |> import(%) for calling function-like keywords,
F# proposal

    value |> x=> x.foo() for method calls,
    value |> x=> x + 1 for arithmetic,
    value |> x=> [x, 0] for array literals,
    value |> x=> ({foo: x}) for object literals,
    value |> x=> `${x}` for template literals,
    value |> x=> new Foo(x) for constructing objects,
    value |> x=> import(x) for calling function-like keywords,
F# proposal would make `await` and `yield` into special syntax cases or not allowed.

I'd rather do await/yield the old fashioned way (or slightly complicate the already complex JS syntax rules) than add the weird extra syntax. Arrow functions are elegant and already well-known and well-understood.

Re: Pipe Operator (|>) For JavaScript

#9

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.

Re: Pipe Operator (|>) For JavaScript

#10
post #9

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.

If you're compiling to javascript anyway, why would you need a pipe operator in javascript instead of just nesting the function calls?
Post reply on HN