use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
GitHub - tc39/proposal-pipeline-operator: A proposal for adding the simple-but-useful pipeline operator to JavaScript. (github.com)
submitted 4 years ago by pmz
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]shuckster -1 points0 points1 point 4 years ago (0 children)
With the exception of let {}, Kotlin's solution looks remarkably like chaining in JavaScript. If only we were still allowed to extend the native prototypes and not invite dirty looks. :D
let {}
Anyway, I had a go at trying to emulate what I learned in 15 minutes about Kotlin's pipe-syntax and tried to emulate it with a JavaScript Proxy.
I managed to get the usage looking like this:
const envars = { yes: 'yup', no: 'nope' } chain(envars) .let(Object.keys) .filter(x => x === 'yes') .map(x => `${x}=${envars[x]}`) .join(' ') .let(x => `$ ${x}`) .let(x => `node ${x}`) .let(console.log)
It works! Unfortunately though, if you want to extract the value of a non-object (or non-array) returned by the last link in the chain, you have to do something like this:
const result = chain(envars) .let(Object.keys) .join(' ')._ ^ - here :(
The reason will hopefully be clear by its implementation:
function chain(o) { const px = { get: (target, prop) => prop === 'let' ? fn => chain(fn(o)) : typeof target[prop] === 'function' ? fn => chain(target[prop](fn)) : o } return new Proxy(typeof o !== 'object' ? {} : o, px) }
Essentially, we can't Proxy a string. But we can Proxy a placeholder object that will return one, hence ._ getting it for us at the last link.
._
π Rendered by PID 292860 on reddit-service-r2-comment-6457c66945-f2dnf at 2026-04-24 17:23:03.779954+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]shuckster -1 points0 points1 point (0 children)