我有课:
export class MapApi {
[reonMap]: Map;
constructor(container: HTMLElement, props: nMapProps = {}) {
this[Map] = new Map(container, libraryUrl, props);
}
}
如何在类外获取this[Map]
的实例new Map
?
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