Bug 782231 - Implement DirectoryIterator.prototype.forEach. r=froydnj

This commit is contained in:
David Rajchenbach-Teller 2012-09-21 23:36:15 -04:00
parent 811fd6492f
commit 544ba638fc

View File

@ -201,6 +201,22 @@ AbstractFile.AbstractIterator.prototype = {
*/
__iterator__: function __iterator__() {
return this;
},
/**
* Apply a function to all elements of the directory sequentially.
*
* @param {Function} cb This function will be applied to all entries
* of the directory. It receives as arguments
* - the OS.File.Entry corresponding to the entry;
* - the index of the entry in the enumeration;
* - the iterator itself - calling |close| on the iterator stops
* the loop.
*/
forEach: function forEach(cb) {
let index = 0;
for (let entry in this) {
cb(entry, index++, this);
}
}
};