javascript/**TheobjecttobeheldwithintheObjectPool.*/functionObj(){this.inUse=false;//Istrueiftheobjectiscurrentlyinuse/**Setsanobjectnotinusetodefaultvalues*/this.init=function(/*values*/){/*codetoinitializeobjecttodefaultvalues*/};/**Spawnanobjectintouse*/this.spawn=function(/*valuesifany*/){/*codetosetvaluesifany*/this.inUse=true;}/**Usetheobject.Returntrueiftheobjectisreadytobe*cleared(suchasabulletgoingofthescreenorhitting*anenemy),otherwisereturnfalse.*/this.use=function(){if(/*objectisreadytobereused*/){returntrue;}else{/*codetouseobject*/returnfalse;}};/**Resetstheobjectvaluestodefault*/this.clear=function(){/*codetoresetvalues*/this.inUse=false;};}/***TheObjectPool.Unusedobjectsaregrabbedfromthebackof*thearrayandpushedtothefrontofthearray.Whenusingan*object,iftheobjectisreadytoberemoved,itsplicesthe*arrayandpushestheobjecttothebacktobereused.*/functionPool(){varsize=20;//Maxobjectsallowedinthepoolvarpool=[];/**Populatesthepoolarraywithobjects*/this.init=function(){for(vari=0;i
javascript對象池是什么鬼來的?求指指點(diǎn)點(diǎn)
溫溫醬
2019-04-13 08:36:37