- From: Marcos Caceres <notifications@github.com>
- Date: Sun, 14 Feb 2016 18:44:39 -0800
- To: whatwg/url <url@noreply.github.com>
- Message-ID: <whatwg/url/issues/90@github.com>
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: 1. URLSearchParams, although not "map-like", is extremely close to an ES Map in look and feel. ES `Map()` returns itself when a developer calls `set()`. Similarly, so do the calls on ES Set(). It is surprising that URLSearchParams does not work the same. 2. Using `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: ```JS function buildQuery(items) { const params = new URLSearchParams(); items .map(item => item.url) // This is not great, requires unnecessary "{ }", ";" x2, and "return" :( .reduce(url => { params.append(); return params; }, params) return params.toString(); } ``` Could become much cleaner: ``` function buildQuery(listOfThings) { return items .map(listOfThings => listOfThings.url) .reduce(url => params.append("foo", url), new URLSearchParams()) .toString(); } ``` //cc @domenic --- Reply to this email directly or view it on GitHub: https://github.com/whatwg/url/issues/90
Received on Monday, 15 February 2016 02:45:11 UTC