This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.
If we change the FormData.append function to return the FormData object on which the function was called, it would allow syntax like myformdata.append("foo", file).append("bar", "text").append("baz", blob); as well as xhr.send((new FormData).append("afile", myfile));
We do not use that pattern anywhere else as far as I know.
That's a terrible reason not to do something! There are lots of things that the DOM didn't used to do but which were a good idea and that we're slowly starting to do now. Do you have a technical reason why you don't think we should provide the nicer syntax in comment 0?
Is it established chaining is a good idea? What other APIs use this?
There are lots of DOM methods that could adopt this syntax. It's one of the things that helps make jQuery concise: you can chain repeated method calls without having to repeat the thing you're calling it on. In many cases you can completely avoid temporaries. Like consider document.body.appendChild(document.createElement("foo") .setAttribute("bar", "baz") .setAttribute("quz", "qoz")); vs. var element = document.createElement("foo"); element.setAttribute("bar", "baz"); element.setAttribute("quz", "qoz"); document.body.appendChild(element); which is one extra line with an extra temporary. Is there any reason we shouldn't adopt this convention across the board for DOM methods with void return type? Compat risk is conceivable, but I shouldn't think it's at all certain, and it seems worth it to try.
Once ECMAScript adopts this pattern, and looking at https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Map it won't, we should consider it, no sooner imo.
I've added an agenda item for the coming TC39 meeting to discuss |this| returns in new API. See also: http://lists.w3.org/Archives/Public/public-script-coord/2012OctDec/0164.html