W3C home > Mailing lists > Public > whatwg@whatwg.org > January 2013

Re: [whatwg] [Notifications] Constructor should not have side effects

From: Bjoern Hoehrmann <derhoermi@gmx.net>
Date: Wed, 30 Jan 2013 02:12:58 +0100
To: Ryosuke Niwa <rniwa@apple.com>
Message-ID: <06rgg8to6ju0gvpgfegid1r6lt8adod3qt@hive.bjoern.hoehrmann.de>
Cc: WHATWG <whatwg@whatwg.org>
* Ryosuke Niwa wrote:
>On Jan 29, 2013, at 10:26 AM, Elliott Sprehn <esprehn@gmail.com> wrote:
>> For example you can do var request = new XMLHttp( .... ) at the start of a
>> function, but then later decide you didn't want to send the request, and
>> never call send().
>
>Is that even a valid use case? It seems dubious to instantiate a class 
>named "request" and then not send a request.

`XMLHttpRequest` tries to encapsulate request, response, user agent, XML
parser, and other things into a single object; that's rather dubious in-
deed, but not the calling code's fault. A more typical object design is
the separation I've just mentioned, in Perl for instance you would use a
LWP::UserAgent object where you might set user agent properties like the
User-Agent header or whether the user agent should follow redirects au-
tomatically, and then use that object for many requests. You might pass
it even to other objects in case they need to make any requests on your
code's behalf; and if they don't need to after all, it's quite normal to
dispose of the object without having made any requests.
-- 
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Am Badedeich 7 · Telefon: +49(0)160/4415681 · http://www.bjoernsworld.de
25899 Dagebüll · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/ 
Received on Wednesday, 30 January 2013 01:13:26 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 30 January 2013 18:48:12 GMT