Say I have a class like so:
class Foo {
constructor(){
this.internalList = new Set([1,2,3])
}
}
is there some method I can implement like so:
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;
}
}
so that I can call this:
const v = Array.from(new Foo());
so is there some interface or method that I can fulfill so that Array.from will work on my class?
Symbol.iterator: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…Setand then it would automatically be iterable as the object itself would be an iterable Set with all the methods and capabilities of aSetobject.