var o: DynamicObject = new DynamicObject();
o.wait(1).die().call(function (){o.addBlood()}).apply();
//или так
o.onCollide(typeWall).die().apply();
interface Contextable {
context:Context;
call(milliseconds: number, func: Function)
wait(milliseconds: number)
apply()
}
class Context {
c:Context;
static globalID: number = 0;
id: number = 0;
f:Function = () => {}
nextF(cb: (end: Function) => any) {
var con = this;
return function () {
//all the previous goes here
if (con.c)
con.c.f.bind(con.c);
cb(con.f);
};
}
constructor (prev: Context, prevF:(end: Function) => any) {
this.c = prev;
this.id = Context.globalID;
Context.globalID++;
if (prevF)
this.c.f = this.nextF(prevF);
}
}
call(milliseconds, func) {
this.context = new Context(this.context, (next: Function) => {
setTimeout(() => {
func();
next();
}, milliseconds);
});
return this;
}