if (typeof Function.bind !== 'function') { Function.prototype.bind = function(scope) { var _function = this; return function() { return _function.apply(scope, arguments); } }; } Drawing.prototype.createDrawFunction = function() { var functioncalls = [], currenttime = new Date().getTime(); if(this.dying || this.temporary) { functioncalls.push(function(ctx) { ctx.save(); }); if(this.dying) functioncalls.push( (function(ctx) { if(this.life < 0.04) this.die(); this.life -= 0.03; ctx.globalAlpha = this.life; }).bind(this) ); if(this.temporary) functioncalls.push(function(ctx) { ctx.shadowOffsetX = 2;ctx.shadowOffsetY = 1;ctx.shadowBlur = 3;ctx.shadowColor = '#000'; }); } if(this.animate) functioncalls.push( (function(ctx) { this.movePen();this.drawPart(ctx); }).bind(this) ); else functioncalls.push( (function(ctx) { this.drawWhole(ctx); }).bind(this) ); if(this.dying || this.temporary) functioncalls.push(function(ctx) { ctx.restore(); }); if(currenttime - this.time_created < 5000) { functioncalls.push( (function(ctx) { ctx.fillText(this.u_name, this.xpos+this.width, this.ypos+this.height); }).bind(this) ); setTimeout( (function() { this.draw = this.createDrawFunction(); }).bind(this), 5000 + 10 - (this.currenttime - this.time_created)); } return (function(ctx) { for(var i = 0, max = functioncalls.length; i < max; ++i) functioncalls[i](ctx); }); };