[whatwg] [Notifications] Constructor should not have side effects
Glenn Maynard
glenn at zewt.org
Tue Jan 29 16:13:01 PST 2013
On Jan 29, 2013 12:07 PM, "Stewart Brodie" <stewart.brodie at antplc.com>
wrote:
> For example, how can you add event listeners to something that doesn't
> exist
yet? Particularly if you want to use a closure with the new object.
>
The same way as always: just attach the listener. You can't "miss" events,
since it's guaranteed that no events will be fired before returning to the
event loop. This is a universal idiom on the platform, FYI.
> Having objects that begin their job when constructed simply avoids an
> > extra step for the user (telling it to start), and reduces the number of
> > possible states (eg. eliminating the UNSENT state), which generally
> > simplifies things. Supporting reuse of objects is generally not a useful
> > optimization (in my experience), so not supporting it also simplifies
> > things a bit. Reducing the number of different-but-equivalent ways of
> > doing the same thing is also generally good API design.
>
> I agree - but I don't see what this has to do with separating construction
> from activation.
>
Object reuse was given as an argument to having a separate send() method,
but allowing object reuse is a bad thing unless there are compelling use
cases for supporting it.
On Tue, Jan 29, 2013 at 12:26 PM, Elliott Sprehn <esprehn at gmail.com> wrote:
> With notifications I can't look at the properties of a
> notification in the web inspector without having it show on me...
>
It doesn't matter if it's being shown or not, if you're just debugging.
Constructors are not verbs. new Notification doesn't mean "show", and new
> XMLHttpRequest doesn't mean "send".
>
I disagree.
> This is pretty standard OO best practices stuff.
I disagree.
Unless you give arguments rather than assertions, there's nothing to argue
against, so all I can do is state my disagreement. Constructors are
essentially nothing but a different syntax for a function that returns an
object of the same type. Some languages, like Python, don't even
differentiate the syntax. There's no implication about side-effects one
way or the other.
--
Glenn Maynard
More information about the whatwg
mailing list