Create  Edit  Diff  XUL Wiki  Index  Search  Changes  History  Source  RSS  wikifarm  Login

nsISimpleEnumeratorを簡単に扱う

面倒なnsISimpleEnumeratorを簡単に扱う方法

function list(_enum,type){
  this._enum=_enum;
  this.type=type;
}
list.prototype={
  cache:new Array(),
  get:function(aNum){
    if(aNum==-1)return;
    if(this.cache[aNum])return this.cache[aNum];
    while(this._enum.hasMoreElements()){
      this.cache.push(this._enum.getNext().QueryInterface(this.type));
      if(aNum==this.cache.length-1)return this.cache[aNum];
    }
    return void(0);
  }
}

是をつかえば

function test(){
var testDir = Components.classes['@mozilla.org/file/local;1']
                .createInstance(Components.interfaces.nsILocalFile);
testDir.initWithPath("/home/nazo");
var entries = testDir.directoryEntries;
entries=new list(entries,Components.interfaces.nsILocalFile);
entries.get(Number.MAX_VALUE);
var test="";
for(i in entries.cache){
    test+=entries.cache[i].leafName+"\n";
}
alert(test);
}

として簡単に利用が可能。

Last modified:2005/10/27 00:24:00
Keyword(s):
References: