I'm asking maybe something too weird but i'm not sure
I'm trying to make .done() function in Typescript using OOP
My code looks like:
// Calling this callback out of Class map/terrain
terrain.done(() =>
{
// Do something when terrain is Done
});
Another code is loading terrain, now i have function whit i want to run this callback.
private loadTiledmap():void
{
.... //loadTiledmap is called when all resources are loaded
this.done; // Trigger the callback
}
public done(callback: () => void ): void
{
callback();
}
The both this.done and terrain.done(() will call the callback, but i have no idea how to trigger terrain.done(() somewhere else in code. Thanks for all your helps and tips
.done()callback (or.then()I suppose) then you'd return aPromisefrom that operation: developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/…done()is called, it will just instantly call the function that was passed to it without waiting! if you would like to attach a callback that can be called later, consider using an EventEmitter, otherwise store the callback whendone()is called (don't call it instantly) and execute that callback if it exists inloadTiledmap()