W3C home > Mailing lists > Public > public-device-apis@w3.org > October 2009

What does it all hang off of?

From: Robin Berjon <robin@berjon.com>
Date: Fri, 2 Oct 2009 14:32:41 +0200
Message-Id: <2FFE7576-882A-480E-8F19-590267FA5F32@berjon.com>
To: public-device-apis@w3.org
Hi all,

one issue we have with APIs is also how they are exposed. Say for  
instance that the Contacts API has a basic interface providing access  
to the rest of the functionality called "Contacts". We could:

1) Make it available as a constructor:

   var cs = new Contacts();
   var mum = cs.findOne({ nickname: "mum" });

This pollutes the global namespace (since "Contacts" is now a variable  
in that scope), and is useless since there's no use for multiple  
instantiation of that class.

2) Make it available as an object already instantiated in the global  
scope:

   var mum = contacts.findOne({ nickname: "mum" });

This is nicer, less useless, but still polluting. Given the number of  
APIs that we have, it's probably a bad idea.

3) Make a way of requesting that an API be "loaded":

   var mum = loadAPI("contacts").findOne({ nickname: "mum" });

This adds only one item to the global scope (which is acceptable), but  
isn't idiomatic.

4) Use an object to provide access to all the device APIs:

   var mum = device.contacts.findOne({ nickname: "mum" });

I think the latter is the cleanest option. Specifying one such  
extensible object is trivial, and would be a very short specification.

Another option is to hang off of the navigator object just like  
geolocation did  but that seems wrong (I'm not sure why it was chosen  
there).

Thoughts?

-- 
Robin Berjon - http://berjon.com/
Received on Friday, 2 October 2009 12:33:11 UTC

This archive was generated by hypermail 2.3.1 : Monday, 23 October 2017 14:53:39 UTC