Additional Feature BC
December 8, 2018 · View on GitHub
| Name | Status | Features | Purpose |
|---|---|---|---|
| Core Proposal | Stage 0 | Infix pipelines … |> …Lexical topic # | Unary function/expression application |
| Additional Feature BC | None | Bare constructor calls … |> new … | Tacit application of constructors |
| Additional Feature BA | None | Bare awaited calls … |> await … | Tacit application of async functions |
| Additional Feature BP | None | Block pipeline steps … |> {…} | Application of statement blocks |
| Additional Feature PF | None | Pipeline functions +> | Partial function/expression application Function/expression composition Method extraction |
| Additional Feature TS | None | Pipeline try statements | Tacit application to caught errors |
| Additional Feature NP | None | N-ary pipelines (…, …) |> …Lexical topics ##, ###, and ... | N-ary function/expression application |
Additional Feature BC
ECMAScript No-Stage Proposal. Living Document. J. S. Choi, 2018-12.
This document is not yet intended to be officially proposed to TC39 yet; it merely shows a possible extension of the Core Proposal in the event that the Core Proposal is accepted.
An additional feature – bare constructor calls – would make constructor calls
terser. It adds a mode to bare style: if a bare-style pipeline step is preceded
by a new, then instead of a function call, it is a constructor call. value |> object.Constructor is equivalent to object.Constructor(value). This is
backwards compatible with the Core Proposal as well as all other additional
features.
Additional Feature BC is formally specified in in the draft specification.
| With smart pipelines | Status quo |
|---|---|
|
|
If a pipeline step starts with new, followed by a mere identifier, optionally
with a chain of properties, and with no parentheses or brackets, then that
identifier is interpreted to be a bare constructor.
That is: if a pipeline is of the form
topic |> new identifier
or topic |> new identifier0.identifier1
or topic |> new identifier0.identifier1.identifier2
or so forth,
then the pipeline is a bare constructor call.
| Valid topic style | Valid bare style | Invalid pipeline |
|---|---|---|
… |> new C(#) | … |> new C | … |> new C() 🚫 |
| ″″ | ″″ | … |> (new C) 🚫 |
| ″″ | ″″ | … |> (new C()) 🚫 |
| ″″ | ″″ | … |> new (C) 🚫 |
| ″″ | ″″ | … |> new (C()) 🚫 |
… |> new o.C(#) | … |> new o.C | … |> new o.f() 🚫 |
… |> new o.C(arg, #) | const f = $ => new o::C(arg, $); … |> f | … |> new o.C(arg) 🚫 |
… |> new o.make()(#) | const C = o.make(); … |> new C | … |> new o.make() 🚫 |
… |> new o[symbol](#) | const f = new o[symbol]; … |> f | … |> new o[symbol] 🚫 |
… |> await new o.make()(#) | const af = new o.make(); … |> await af | … |> new await o.make() 🚫 |
[Unix pipe]: https://en.wikipedia.org/wiki/Pipeline_(Unix
[untangled flow]: ./goals.md#untangled-flow
[Visual Basic’s select statement]: https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/select-case-statement
[WebKit console variables]: https://webkit.org/blog/829/web-inspector-updates/
[WHATWG Fetch + CP]: ./core-real-examples.md#whatwg-fetch-standard
[WHATWG Fetch Standard]: https://fetch.spec.whatwg.org/
[WHATWG Streams + CP + BP + PF + NP]: ./additional-feature-np.md#whatwg-streams-standard-core-proposal--additional-features-bppfmt
[WHATWG Streams + CP + BP + PF]: ./additional-feature-pf.md#whatwg-streams-standard-core-proposal--additional-feature-bppf
[WHATWG Streams Standard]: https://stream.spec.whatwg.org/
[WHATWG-stream piping]: https://streams.spec.whatwg.org/#pipe-chains
[Wikipedia: term rewriting]: https://en.wikipedia.org/wiki/Term_rewriting
[zero runtime cost]: ./goals.md#zero-runtime-cost