Hi,
I'm having fun documenting the Wifi API :-)
I have a question regarding something I read on the IDL file [1] (I
don't have a device with remote debugging working around me, I'll
probably test when I do)
/**
* Returns the list of currently available networks.
* onsuccess: We have obtained the current list of networks.
request.value
* is an object whose property names are SSIDs and
values are
* network objects.
* onerror: We were unable to obtain a list of property names.
*/
nsIDOMDOMRequest getNetworks();
In theory, it feels like a good idea, but in practice, objects in
JavaScript aren't that nice. I worry that naive code playing with this
kind of objects may break in a way or another if someone has fun
renaming its SSID to "__proto__", "__noSuchMethod__" (magic property
names) or "hasOwnProperty" (shadowing issues with Object.prototype).
After some investigation, it looks like it's actually an array or
array-like object [2]. Is the comment outdated?
I don't have strong opinions (yet :-) ) on what the API should look
like, but for string->value data structures, please prefer ES6 Maps [3]
as they won't have the magic property and shadowing/collision hazards
that objects have.
David
[1]
http://mxr.mozilla.org/mozilla-central/source/dom/wifi/nsIWifi.idl?raw=1
[2]
https://github.com/mozilla-b2g/gaia/blob/079b57f45f2e272ceb4e0f3f067cc3d829b3f2b4/apps/settings/js/wifi.js#L331-L334
[3]
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map