-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use @
instead of ?
character and proposal about ...
#37
Comments
"@" certainly does imply location to me more than the others. |
Are the numbered versions of the operator needed? func(@, @, 42) meaning (p1, p2) => func(p1, p2, 42) seems pretty intuitive and readable to me. I guess the numbered placeholders would open up the possibility to pass the same argument multiple times, as in (p1) => func(p1, p1, 42) but how often is that needed really? |
Related (possibly duplicated): #21 |
If partial application were only intended to be used with pipeline, then the numbered version's wouldn't be useful on their own. However, the proposal is intended to be more useful than that specific scenario. One of the purposes of numbered placeholders is to allow you to adapt one function to be used as an input to another function: // package "a"
/**
* @param {string} str
* @param {number} num
*/
export function doSomething(str, num) { ... }
// package "b"
/**
* @param {function(number,string):*} fn
*/
export function acceptCallback(fn) { ... }
// app.js
import { doSomething } from 'a';
import { acceptCallback } from 'b';
acceptCallback(doSomething(?1, ?0)); // swaps arguments |
Each of them is reasonable for this proposal. |
Current JS development seems to go more and more towards towards enhanced tooling. I would hope for different styles for ternary I'm not sure if "can be written in confusing way" is something that I would be willing to pay to get rid of. "Can be validly interpreted in many ways" instead is a real issue. Choosing |
I'm all for switching up the character to something less overloaded, but Personally I love I think this becomes even stronger if numbered placeholders are sort of reframed as Central to the proposal, with non-numbered placeholders being framed as a convenient shorthand for the common case. |
Couldn't agree more. That's just like |
I'm concerned about using |
That said, I agree with @nicolo-ribaudo that this is essentially a duplicate of #21. Further discussion should be moved to that issue. |
|
Use
?
There are already many operators use the
?
character.There will be some confusing cases:
Use
(?)
instead of?
can fix some problem, but why no try a distincter charactor?Use
@
The only usage of
@
is for decorator in the future, as decorator, there must be an identifier follow@
without space between. But as placeholder, we only put.
,(
,,
or number after@
. It's easy to distinguish.Add number after
@
also more readable then?
Extensible for Placeholder In Expression
That's not in this proposal, but let's take a sight on future possibility. Suppose we've got a considered priority rule, and allow placeholder in expressions. Here is a example not complete but show some possible:
about
...
...
has two meanings: spread and rest. So there will be 3 different case:So we need add two more styles.
Here are examples to show why these are reasonable:
The text was updated successfully, but these errors were encountered: