Reputation: 12015
I have a class:
export class MapApi {
[reonMap]: Map;
constructor(container: HTMLElement, props: nMapProps = {}) {
this[Map] = new Map(container, libraryUrl, props);
}
}
How to get instance this[Map]
of new Map
outside class?
Upvotes: 1
Views: 613
Reputation: 26170
TypeScript supports getters/setters
as a way of intercepting accesses to a member of an object. In your class, this can be implemented as follows:
export class MapApi {
private _reonMap: Map;
constructor(container: HTMLElement, props: nMapProps = {}) {
this._reonMap = new Map(container, libraryUrl, props);
}
get reonMap(): Map {
return this._reonMap;
}
}
To access it outside of the class
, do the following:
const mapApi = new MapApi(...);
const reonMap = mapApi.reonMap;
Upvotes: 1