[英]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. 我正在用打字稿为我的框架实现DI容器,并且想知道我的类构造函数的参数和实例化属性。 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. 我将接口名称IDriver传递为字符串(因为无法将接口作为参数传递)和具体的类DriverA传递给我的注册例程。 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.
在解析状态下,要实例化DriverA,我得到了构造函数和Drive方法,但找不到诸如Tickets和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
. 注意
this.Tickets
。 PS: they only get added after the constructor is called. PS:仅在调用构造函数后才添加它们。 ie
new DriverA()
即
new DriverA()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.