updateDOM
?enemy.prototype.move = function(updateDOM) {
this.x++;
var chance = Math.random();
if(chance > 0.5) {
this.y++;
}
if(updateDOM)
this.updateDOM();
}
this
переводить в переменную и как тут работает this._interval
?enemy.prototype.runMoving = function(){
var self = this;
this._interval = setInterval(function() {
self.move(true);
}, 100);
}
enemy.prototype.stopMoving = function(){
if(this._interval){
clearInterval(this._interval);
this._interval = undefined;
}
}
one.el?
function create() {
var one = new enemy();
document.querySelector(".boris").appendChild(one.el);
return one;
}
var alice = create();
var bob = create();
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 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);
}