I am working on a snippet and in my research I see that the options
property of the select object is a collection, not an array. I am
having great difficulty finding any good, comprehensive documentation on
javascript collections and their methods. Can anyone point me to a good
reference?
What makes you call it a "collection?" Are you just using that as a
generic term for things that are like arrays but are not really
arrays? I tend to do that also; afaik "collection" has no predefined
meaning in js/es, so it seems safe to use as a generic word for things
like that... but because it's just a generic word, you won't find any
references on "collection" as if it were a real 'datatype' (ctor
function).
Chrome calls it a NodeList, as Gregor mentioned. Firefox doesn't seem
to have a special name for it, unless I've totally forgotten how to
use firebug since switching to chrome.
Check this out, it might be useful to you. Try putting it into the
chrome console one statement at a time. It'll work in ff/firebug too,
although the console.log lines seem pretty useless there.
// get a collection of nodes
var foo = document.getElementsByTagName('div');
// what kind of object is "foo?"
console.log(foo.constructor.prototype);
// --console output from previous line--
//
// Object
// constructor: function NodeList() { [native code] }
// item: function item() { [native code] }
// __proto__: Object
// so it's a NodeList. Looks like NodeList has a method named
// "item," but not much else.
// ...so maybe we'd be better off with an Array; it can do a lot
// more than a NodeList... Here's a trick (it's been discussed
// here before) to turn a array-like object into a true array.
foo = [].slice.call(foo);
// did it work?
console.log(foo.constructor.prototype);
// (shows prototype for Array ctor)
// let's see if we can use Array methods on "foo" now.
foo.reduce(function(p, n){
return (p.innerHTML || p) + n.innerHTML
}, '');
While we are on the subject of references I'm open to suggestions in
general.
I like developer.mozilla.org, pretty thorough and straightforward,
good about pointing out deviations from standard. In general it seems
like most of the docs at moz pertain to most of the modern non-IE
browsers, but not so much IE, so it can be good to compare moz docs to
the docs on MSDN whenever you get around to hacking in IE support.
I prefer to have down-loadable, searchable references because
I hop back and forth between many, and the differences sometimes blur.
Downloadable and searchable? You probably want those ECMAScript pdfs.
I'm sure someone here has a link. Those seem to be more targeted at
browser vendors than javascript programmers, though, so they can be
quite verbose. Also wget and grep are your friends.
I frequently have trouble remembering language specific semantics and
terminology, (i.e. I may remember that something exists, and what it
is/does, but can't remember what it's called in that particular
language.) but I can usually search and find things that remind me of
what I'm looking for, and where to look for it.
You could check out visibone's cheat sheets at
www.visibone.com/javascript
I haven't recommended these in years because I don't use them myself
(I've seen them in print, though, they're good) but it sounds like the
kind of quick reference you might be looking for.