- From: David Bruant <bruant@enseirb-matmeca.fr>
- Date: Sat, 24 Apr 2010 23:59:22 -0700
>> // turning live collection into static array fixes this >> >> Array.slice(document.getElementsByTagName('div')).forEach(function(el) { >> el.parentNode.removeChild(el); >> }); >> >> > Where supported, though top level generics such as Array.slice are not > standard, so: > > var divList = document.getElementsByTagName('div'); > Array.prototype.slice.call( divList ); > > Elsewhere: > https://mail.mozilla.org/pipermail/es-discuss/2009-December/010241.html > Ok. I understand the "Array.slice" now. Sorry. "Array.prototype.slice.call( divList );" is not standard either. In ECMAScript 5, it is stated that : "The slice function is intentionally generic; it does not require that its this value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method. Whether the slice function can be applied successfully to a host object is implementation-dependent." Somehow, the reason why I am proposing that HTMLCollections inherit from Array.prototype is to get rid of the "implementation-dependant" for HTMLCollections which are clearly very good candidates for methods such as forEach, filter (returns a new array (which would be a convinient way to create static copies in one call)) or some/every. David
Received on Saturday, 24 April 2010 23:59:22 UTC