简体   繁体   English

覆盖Angular2上的JavaScript NAME属性(打字稿)

[英]Override JavaScript NAME property on Angular2 (typescript)

I'm using draw2d on angular2 (draw2d-wrapper). 我在angular2(draw2d-wrapper)上使用了draw2d。 I'm trying extend a class from them. 我正在尝试从他们那里扩展一堂课。

export class Table extends (draw2d.shape.layout.VerticalLayout as { new(): any }) {
    static NAME: "Table";
    /*Some code*/
}

on my code when I do var t = new Table(); 在我的代码上,当我做var t = new Table();

the t.NAME property came as "draw2d.shape.layout.VerticalLayout". t.NAME属性的名称为“ draw2d.shape.layout.VerticalLayout”。

Can I override this JavaScript property in a angular2 typescript code? 我可以在angular2打字稿代码中覆盖此JavaScript属性吗?

Since you are trying to access the property on your table instance, it's not really a static property. 由于您尝试访问表实例上的属性,因此它并不是真正的静态属性。 Simplifying your example, this works: 简化您的示例,可以使用:

class VerticalLayout {
  NAME = "VerticalLayout";
}

class Table extends VerticalLayout  {  
  NAME = "Table";
}

new Table().NAME; // Table

I would expect the same to work for deriving from draw2d.shape.layout.VerticalLayout 我希望从draw2d.shape.layout.VerticalLayout派生相同的draw2d.shape.layout.VerticalLayout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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