Mouse is a class, has its own member variable and member method, the member method must add prototype, avoid JS prototype pit.
varMouse =function(ID) { This. ID =ID; This. Name = ""; This. Mes =NULL;//The div that was created This. con =NULL; This. Runawayinterval =NULL; This. Init ();}; Mouse.prototype.init=function(){ //Console.log ("Initialization id" + this.id + "mouse"); This. Show (); Mouse.prototype.show=function(){ This. Mes = document.createelement ("div"); This. Mes.setattribute ("id", "Mickey"); This. con = document.getElementById ("Container"); This. mes.style.opacity = 1; This. Con.appendchild ( This. Mes); This. Mes.onclick =function() {getscore (); This. Con.removechild ( This. Mes); Clearinterval ( This. Runawayinterval); Removeonemouse ( This. ID); }.bind ( This); //Console.log (this.con.offsetwidth-100); This. Mes.style.left = Math.random () * ( This. con.offsetwidth-100). ToString () + "px"; varTargettop = Math.random () * ( This. con.offsetheight-100) +50; This. mes.style.top =targettop + "px"; //this.mes.style.top = 0 + "px"; This. Runawayinterval = SetInterval ( This. Runaway.bind ( This), 200);} Mouse.prototype.runAway=function(){ //Console.log ("I Am" "+ this.id +" ' I am running ... "); varOPA = parsefloat ( This. mes.style.opacity); Opa-= 0.1; This. mes.style.opacity =Opa; if(opa<=0) { This. Lose (); }}//Mouse.prototype.beCatch = function ()// {//This.con.removeChild (this.mes);//clearinterval (this.runawayinterval);// }Mouse.prototype.lose=function(){ //Console.log ("I am" + this.id + "' I have successfully skipped ..."); This. Con.removechild ( This. Mes); Clearinterval ( This. Runawayinterval); Removeonemouse ( This. ID); Losescore ();}
Native JS object-oriented notation