-
Notifications
You must be signed in to change notification settings - Fork 136
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
URLSearchParams: calling .set() and .append() should return itself #90
Comments
(fixed up first code example above) |
This pattern of returning this is not something TC39 is still advocating I believe. That's why we didn't copy it. It makes it impossible to introduce a useful return value in the future. |
Ok, sent to public-script-coord, to hopefully get a little more ocntext. Closing for now. |
Reopening, as there was support on public-script-coord for adding this. |
The reason I haven't done this yet by the way is that the support was not overwhelming and there's other differences between |
It would be good to do it for all of them tho (and because they currently return undefined, it might mean that this can be done in a somewhat backwards compatible way). This not returning self might become an issue - in as far that it's another place where the platform doesn't match ES! - as more people start migrating to ES6 and beyond, because all other map/set interfaces return self. This makes these interfaces annoying to use when writing functional code. Would it help to get more opinions from functional programming folks? |
What returns undefined currently? I actually think not matching ES is a feature here. If we ever wanted to return something meaningful, we still have the option to do so... |
.append() and friends.
I'd be interested to hear how it's a feature to break with ES? What are the benefits for devs? |
Oh, I was talking about
As was pointed out on public-script-coord what ES does doesn't make much sense. It's totally unclear what methods will return this and what methods will return something else. And if we ever got to a point where |
Ah. Yeah, that can be nice when the multi-map is typed.
I agree that for some APIs that might be the case, but there is only a limited set of operations for Map/Set-like things. It's pretty easy to map them to ES and match the behavior (e.g., when you add and append stuff).
Sure, but that would be fairly exceptional... thus throw, no? Anyway, if it's just me that things it's a bit annoying then I'm ok to close this - but I keep hitting it. Wish we had some way of gathering better developer feedback about this kind of thing. Running a totally unscientific poll about it: |
Another thing I was thinking, for a multimap you might want |
That seems to duplicate what
It's what @jussi-kalliokoski said on Twitter: "consistency and least surprise". The current design violates both, because:
Consider again what we have today: .reduce((params, url) => {
params.append("foo", url);
return params;
}, params) So, the utility in returning self is that // Look ma! no return keyword and no "{" or "}"
.reduce((params, url) => params.append("foo", url), new URLSearchParams()) It's extremely common to want to |
To be clear, the point of the poll is to find out of developers actually give a crap (or not!) about these things - I know I do, which is why I raised this issue. If other web devs don't really care about consistent API surface across Web APIs, then this is a non-issue. I know it's out of scope of this bug, but is there a better way for us to find this stuff out from Web developers? I feel like when I raised things as a web developer there is an implicit "but Marcos, you are not a REAL web developer: you are just some clown on the Internet who sends a lot of emails, so you don't really count." Is there a trusted set of Real Web Developers™️ whose opinions would be of value here? |
I'm going to close this as this hasn't really come up again in the intervening years and everyone seems wary of making changes to this API. |
Given a list of search params (strings) to be inserted into a URLSearchParams object, it would be useful if calling .set() and .append() would return the instance of URLSearchParams. Two reasons:
Map()
returns itself when a developer callsset()
. Similarly, so do the calls on ES Set(). It is surprising that URLSearchParams does not work the same.listOfURL.reduce()
(or other functions that operate on lists that expect an object in return) would benefit from this.Consider, this would allow the following code:
Could become much cleaner:
//cc @domenic
The text was updated successfully, but these errors were encountered: