假设我有一个这样的类:
class Foo {
constructor(){
this.internalList = new Set([1,2,3])
}
}
有没有什么方法可以像这样实现:
class Foo {
constructor(){
this.internalList = new Set([1,2,3])
}
toArray(){ // add this method
const ret = [];
for(const v of this.internalList){
ret.push(v);
}
return ret;
}
}
所以我可以这样叫它:
const v = Array.from(new Foo());
那么,有没有什么接口或方法是我可以实现的,这样Array.from就可以在我的类上工作呢?
转载请注明出处:http://www.fulida88.com/article/20230526/2216316.html