var Animal=function(id){
this.onGo=new Publisher();
this.id=id;
this.domElement=$('#'+id);
this.from=parseInt(this.domElement.css('left'));
}
Animal.prototype.go=function(to,duration){
var start = new Date().getTime();
var that=this;
setTimeout(function() {
var now = (new Date().getTime()) - start;
var progress = now / duration;
if(progress > 1) progress = 1;
var result = (to - that.from) * progress + that.from;
that.domElement.css('left', result+'px');
that.onGo.deliver(progress);
if (progress < 1)
setTimeout(arguments.callee, 10);
}, 10);
}
var that=this;
Animal.prototype.go=function(to,duration){
var start = new Date().getTime();
var that=this;
setTimeout(function() {
var now = (new Date().getTime()) - start;
var progress = now / duration;
if(progress > 1) progress = 1;
var result = (to - that.from) * progress + that.from;
that.domElement.css('left', result+'px');
that.onGo.deliver(progress);
if (progress < 1)
setTimeout(arguments.callee, 10);
}, 10);
}
var that=this;
- сохранение контекста (ссылки на объект) в переменную.