this - PreloadJS + Typescript -


i have been stuck 4 days going on so!

please reference preloadjs definitions:

https://github.com/borisyankov/definitelytyped/blob/master/preloadjs/preloadjs.d.ts

from line 26.

my question is, how addeventlistener in typescript while binding class scope?

imagine (semi psudo):

class test {      private _loader:createjs.assetloader;       constructor()      {           this._loader = new createjs.assetloader();           this._loader.addeventlistener(???????????);           this._loader.load();      }       onloadcomplete(???): ???      {       } } 

using typescript 0.9.1.0:

class test {      private _loader: createjs.assetloader;       constructor()      {           this._loader = new createjs.assetloader();           this._loader.addeventlistenerthis.onloadcomplete);           this._loader.load();      }       onloadcomplete = () =>      {         console.log(this.whatever);      }; } 

the important part here using member initialization syntax (member = value) onloadcomplete , using fat arrow lambda expression (() => { ... }) function. correctly capture this context in callback.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -