简体   繁体   中英

how can I access typescript class public property at run time (debugging)? only the constructor and functions are accessible

I am implementing a DI container for my framework in typescript, and want to know my class constructor parameters and properties for instantiating. Here is an example:

interface IDriver 
{
    Drive(): void
}

class DriverA implements IDriver 
{
    public Tickets: Array<Ticket>;
    public Name: String;

    public Drive() {
        //Driving...
    }
}

I am passing the interface name IDriver as string (because I was not able to pass the interface as a parameter) and concrete class DriverA to my registration routine. Latter in resolving state, to instantiate DriverA, I got the constructor and the Drive method, but I can't find the properties such as Tickets and Name. How can I access those properties? is it possible?

Properties are only available if you initialize them eg:

class DriverA 
{
    public Tickets = [];
    public Name = "";

    public Drive() {
        //Driving...
    }
}

will generate :

var DriverA = (function () {
    function DriverA() {
        this.Tickets = [];
        this.Name = "";
    }
    DriverA.prototype.Drive = function () {
        //Driving...
    };
    return DriverA;
})();

Notice this.Tickets . PS: they only get added after the constructor is called. ie new DriverA()

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