admin管理员组

文章数量:1023738

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()

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()

本文标签: