第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

javascript對象池是什么鬼來的?求指指點(diǎn)點(diǎn)

javascript對象池是什么鬼來的?求指指點(diǎn)點(diǎn)

溫溫醬 2019-04-13 08:36:37
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
查看完整描述

2 回答

?
縹緲止盈

TA貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個(gè)贊

1.對象池是什么
關(guān)于這個(gè)樓上說的很清楚。不再重復(fù)。
2.應(yīng)用場景
那種畫面有列表的情況。比如新聞列表,所有的新聞可以當(dāng)成一個(gè)對象池,每條新聞就是其中的每個(gè)object.
新聞的CRUD對應(yīng)的就是object的各種方法。
這種在前端MVC中有類似于collection的概念。
3.好處
代碼組織的比較好,邏輯清晰,易于維護(hù)。如果說關(guān)于性能優(yōu)化啥的,我覺得吧別啥明顯的優(yōu)勢,當(dāng)然這也要看跟啥比吧。
總之,還是比較推薦這種編程風(fēng)格。
                            
查看完整回答
反對 回復(fù) 2019-04-13
?
慕碼人8056858

TA貢獻(xiàn)1803條經(jīng)驗(yàn) 獲得超6個(gè)贊

對象池還第一次聽說,按照博主給出的例子,不難看出對象池就是用來性能優(yōu)化的。
用法代碼還是挺清楚的,從對象池中取可用對象(use)、取最后一個(gè)對象(get)。。
                            
查看完整回答
反對 回復(fù) 2019-04-13
  • 2 回答
  • 0 關(guān)注
  • 697 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號