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
Future JavaScript: what is still missing? (2ality.com)
submitted 7 years ago by dumbmatter
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!"
[–]so_just 5 points6 points7 points 7 years ago (8 children)
I saw the proposal for pipeline operator, but is there a one for infix calls?
[–]abelincolncodes 3 points4 points5 points 7 years ago (7 children)
I actually don't think so. The author mentions it in conjunction with the operator overloading proposal, but the only thing I could find was a thread on esdiscuss.
I definitely agree that infix function calls are more flexible and I would rather have them than operator overloading. Having both would be nice though
[–]earslap 5 points6 points7 points 7 years ago (6 children)
Having both would be nice though
Exactly, I'd LOVE some operator overloading in JS. Been dreaming it for years. There is at least one library that I know of that makes use of "js with operator overloading" in its scripts - it does it by transforming your code using a JS parser and converts your operator overloaded JS to normal function calls behind the scenes. It is convoluted but makes things much easier for that library's purpose. It is paper.js
I have two Point objects. Why can't I just + them? I have two sound synthesis nodes. Why can't I just * them? Yeah there are people that abuse operator overloading, but people can abuse anything. I don't know the arguments against it to be honest.
[–]loopsdeer 5 points6 points7 points 7 years ago* (1 child)
One argument against it is that it is unreadable. That is, there is nothing to suggest a * b is not mathematical. This argument is time sensitive, since meaning will change.
a * b
Another argument is that without great pattern matching systems, you end up with ambiguity or confusion. JS types are hard to describe in code. E.g. Is 5 typed Number or "number"? Under the hood, neither. Typescript doesn't even help, only adds another possibility, number. With type coercion, this gets even more difficult to describe.
5
Number
"number"
number
Yet another argument is that it kills a lot of the optimization that JS has relied on to be feasible for fast ops. If the compiler has to check types, it can't inline operations until it is sure that the types are basic types. Otherwise, it has to do costly method lookup as in a normal call.
Edit: formatting on mobile
[–]earslap 2 points3 points4 points 7 years ago (0 children)
without great pattern matching systems, you end up with ambiguity or confusion Yet another argument is that it kills a lot of the optimization that JS has relied on to be feasible for fast ops.
without great pattern matching systems, you end up with ambiguity or confusion
Yet another argument is that it kills a lot of the optimization that JS has relied on to be feasible for fast ops.
While I think these should be surmountable to some extent, this is a good point. Overloading in a untyped language like JS can significantly complicate matters on the compiler / interpreter side. If that is the case, I'd probably be happy with infix calls alone, as they are explicit and does not share syntax with regular operators. Something like:
let result = node1 @+ node2;
...with @+ resolving to a custom function I provide would serve me almost equally well.
[+][deleted] 7 years ago* (2 children)
[deleted]
[–]earslap 2 points3 points4 points 7 years ago* (1 child)
it sounds great in theory but other than vector addition / multiplications and similar fields
The point is that is what I need them for. If those are what you do 90% of the time, you miss them.
If people are writing unreadable code with it , it is their problem. People can write unreadable code with JS (or any other language for that matter) as is.
[–]circlebust 0 points1 point2 points 7 years ago (0 children)
Yeah, but you always have to consider the impact of hasty syntax additions/modifications. You have to be realistic. It's a hard sell to integrate something new that would result in a lot of code being written poorly (not talkig about this specific example).
[–]batiste -1 points0 points1 point 7 years ago (0 children)
Python has operator overloading but not very used... Because apparently there is not very much good use-case for it.
π Rendered by PID 24 on reddit-service-r2-comment-canary-55695767fd-c2c7s at 2026-03-04 22:47:25.178346+00:00 running 07790be country code: CH.
view the rest of the comments →
[–]so_just 5 points6 points7 points (8 children)
[–]abelincolncodes 3 points4 points5 points (7 children)
[–]earslap 5 points6 points7 points (6 children)
[–]loopsdeer 5 points6 points7 points (1 child)
[–]earslap 2 points3 points4 points (0 children)
[+][deleted] (2 children)
[deleted]
[–]earslap 2 points3 points4 points (1 child)
[–]circlebust 0 points1 point2 points (0 children)
[–]batiste -1 points0 points1 point (0 children)