如何在课堂外获得财产?

问题描述 投票:0回答:1

我有课:

export class MapApi {
  [reonMap]: Map;

constructor(container: HTMLElement, props: nMapProps = {}) {
    this[Map] = new Map(container, libraryUrl, props);
  }

}

如何在类外获取this[Map]的实例new Map

typescript typescript2.0
1个回答
0
投票

TypeScript支持getters/setters作为拦截对对象成员的访问的一种方式。在您的课程中,可以如下实现:

getters/setters

要在export class MapApi { private _reonMap: Map; constructor(container: HTMLElement, props: nMapProps = {}) { this._reonMap = new Map(container, libraryUrl, props); } get reonMap(): Map { return this._reonMap; } } 之外访问它,请执行以下操作:

class
© www.soinside.com 2019 - 2024. All rights reserved.