typescript this cannot be referenced inside a module body -
i have module
module nganimaltracker { export class traycontroller implements itraycontroller{ public starttracker() { var monitor = new animalpositionmonitor(this); this.animaltrackerservices.trackposition(monitor, this.errorcallbackfn); } } } var animalpositionmonitor: = (() => { var jsclass: = (traycontroller: itraycontroller) => { **var monitor = this;** var me: igenxstreamhandler<ianimal> = new genxstreamhandler('animal'); me.process = animal => { var ll = **monitor["traycontroller"].gridoptions.data.length**; } } } if don't have module works. need keep module, need monitor["traycontroller"] access element on process call won't lose scope. how do this?
based on new animalpositionmonitor(this); should refactor animalpositionmonitor class calling new.
going furhter code adding stuff me of type stream handler. pass in this use lambda, no need capture this in variable monitor.
class animalpositionmonitor{ constructor(traycontrller:itraycontroller){ var me: igenxstreamhandler<ianimal> = new genxstreamhandler('animal'); me.process = animal => { var ll = this["traycontroller"].gridoptions.data.length**; } } } this quick video should understand this better : https://www.youtube.com/watch?v=tvocucbcupa
Comments
Post a Comment