This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 13681 - Make FormData.append return the FormData object
Summary: Make FormData.append return the FormData object
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: XHR (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
Depends on:
Reported: 2011-08-05 05:41 UTC by Jonas Sicking (Not reading bugmail)
Modified: 2012-11-22 21:58 UTC (History)
3 users (show)

See Also:


Description Jonas Sicking (Not reading bugmail) 2011-08-05 05:41:19 UTC
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));
Comment 1 Anne 2011-08-05 08:23:58 UTC
We do not use that pattern anywhere else as far as I know.
Comment 2 Jonas Sicking (Not reading bugmail) 2011-08-17 16:53:09 UTC
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?
Comment 3 Anne 2011-08-17 22:19:07 UTC
Is it established chaining is a good idea? What other APIs use this?
Comment 4 Aryeh Gregor 2011-08-17 22:21:20 UTC
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

    .setAttribute("bar", "baz")
    .setAttribute("quz", "qoz"));


  var element = document.createElement("foo");
  element.setAttribute("bar", "baz");
  element.setAttribute("quz", "qoz");

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.
Comment 5 Anne 2012-11-21 21:25:51 UTC
Once ECMAScript adopts this pattern, and looking at it won't, we should consider it, no sooner imo.
Comment 6 Rick Waldron 2012-11-22 21:58:14 UTC
I've added an agenda item for the coming TC39 meeting to discuss |this| returns in new API. See also: