Reputation: 113
I'm working on a leaflet map using typescript. To add some logic to a custom marker I'm extending the L.Marker class.
export class FeatureMarker extends L.Marker {
This is working for me, but now I want to add some custom events. I saw some examples online (e.g. http://www.html5gamedevs.com/topic/611-events-andor-callbacks/), but they require me to extend another class. Which, as far as I understand, is not possible with java/typescript.
So I'm looking for a way to trigger events from within a FeatureMarker instance.
Any suggestions?
Upvotes: 1
Views: 363
Reputation: 275819
but they require me to extend another class. Which, as far as I understand, is not possible with javascript/typescript.
Yes you cannot do multiple inheritance.
So I'm looking for a way to trigger events from within a FeatureMarker instance.
You can do it with a mixin, Reference: https://typescript.codeplex.com/wikipage?title=Mixins%20in%20TypeScript
Alternatively (and better IMHO) just use composition:
export class FeatureMarker extends L.Marker {
emitter : EventObj = new EventObj();
Upvotes: 1