Re: Some comments on the API

On Sun, Oct 17, 2010 at 11:26 AM, Jonas Sicking <jonas@sicking.cc> wrote:
> On Sun, Oct 17, 2010 at 9:16 AM, Doug Turner <dougt@dougt.org> wrote:
>>>  Per the current specification it would be at window.Notification, to be exact.
>>
>> Right.  I am not an advocate of putting this on window.  This is unlike alert(), confirm(), prompt() which are tied to a dom window.  This api is tied more to a user agent itself, and for that, we use navigator.*.
>
> I think the point Anne is trying to make is that as long as we return
> an object of a sort, that object is going to have an interface. And
> since it uses an interface, in this case Notification, we will be
> exposing a so called interface-object in the global scope. We do this
> for almost all interfaces, for example you can do
>
> window.Node
> window.Element
> window.XMLHttpRequest
> window.MouseEvent
> window.HTMLInputElement
>
> These interface objects are mainly useful for two things, it allows
> you to extend objects by doing:
>
> window.Node.prototype.removeFromParent = function() {
>  this.parentNode.removeChild(this);
> }
>
> and by testing that an object is of a particular type
>
> if (someElement instanceof HTMLInputElement) {
>  ..do stuff..
> }
>
> Anyhow, since with this proposed interface we would be using a new
> Notification interface, and thus add its interface-object to the
> global scope, we already have added window.Notification. And so if we
> allow the syntax
>
> x = new Notification;
>
> we don't actually add any *additional* risk of collisions.
>
> / Jonas
>
>

For what it's worth, the current draft has specified accessing
notifications from the navigator object for quite some time.  See
section 5 [1]: "In page context, the NotificationCenter methods are
accessed from the Navigator object."

[1] http://dev.w3.org/2006/webapi/WebNotifications/publish/Notifications.html#window

Received on Monday, 18 October 2010 16:31:37 UTC