Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a helper to work with Enumerables #88

Open
orellabac opened this issue Jan 2, 2021 · 1 comment
Open

Provide a helper to work with Enumerables #88

orellabac opened this issue Jan 2, 2021 · 1 comment

Comments

@orellabac
Copy link

Many COM objects use the _NewEnum mechanism to iterate. A Helper can be provided to make this easier.

@orellabac
Copy link
Author

I tried to create a PR but I found no build scripts. In general my idea is that you can export a class like:

class COMIterator {
    constructor(obj) {
        this.obj = obj;
        this.iter = this.obj._NewEnum;
    }
    [Symbol.iterator]() {
        var localIter = this.iter;
        return function*() {
            if (localIter) {
                var value = undefined;
                do {
                    value = localIter.Next();
                    if (value !== undefined)
                        yield value;
                } while(value !== undefined);
            }
        }();
    }
}

and create a function Iter like

var Iter(obj) => new COMIterator(obj)

and then you can have code like:

  var fso = ActiveXObject("Scripting.FileSystemObject");


    console.log( "Read Drive Letter");
    for(const dir of Iter(drives)) {
      console.log( dir.DriveLetter);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant