最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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?

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?

Share Improve this question asked Dec 12, 2013 at 1:56 yalemyalem 11 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Properties are only available if you initialize them e.g:

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. i.e new DriverA()

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论