简体   繁体   中英

Can I use typescript.js to do some language parsing?

Given the following code:

class Foo
{
    Bar(name: string): void
    {
        var x = name;
    }

    FooBar(): void
    {
    }
}

Using the typescript.js or something, is it possible to list all methods of the class Foo ? How?

If possible I would like to do that without having to compile and run the Javascript. If there is no way I will try my luck with some regex...

You don't need typescript.js or anything similar, just use getOwnPropertyNames such as

var classMemberNames = Object.getOwnPropertyNames(Foo.prototype);

Methods of a TypeScript class appear on the prototype property of the constructor function representing the class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM