いろいろなものを配列に変換する
HTMLElement.prototype.to_a=function()Array.slice(this); Element.prototype.to_a=function()Array.slice(this); HTMLCollection.prototype.to_a=function()Array.slice(this); XPathResult.prototype.to_a=function(){ var r=[]; switch(this.resultType){ case XPathResult.ORDERED_NODE_SNAPSHOT_TYPE: case XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE: for(var i=0;i<this.snapshotLength;i++)r.push(this.snapshotItem(i)); break; case XPathResult.ORDERED_NODE_ITERATOR_TYPE: case XPathResult.UNORDERED_NODE_ITERATOR_TYPE: var i; while(i=this.iterateNext())r.push(i); break; case XPathResult.STRING_TYPE: r.push(this.stringValue); break; case XPathResult.NUMBER_TYPE: r.push(this.numberValue); break; case XPathResult.BOOLEAN_TYPE: r.push(this.booleanValue); break; case XPathResult.FIRST_ORDERED_NODE_TYPE: case XPathResult.ANY_UNORDERED_NODE_TYPE: r.push(this.singleNodeValue); break; } return r; }
document.evaluate('//a',document,null,0,null).to_a()のように使う。