对象池的基本实现
import _ from "lodash";
//marker对象池
let markerMgr = {
_idCounter:0,
_pool:[],
_outPool:{},
_reset(ins){
var m = this;
},
//归还
reback(ins){
var m = this;
m._reset(ins);
delete m._outPool[ins.$$$id];
m._pool.push(ins);
},
//借取
pick(){
var m = this;
var marker;
if(!m._pool.length) {
marker = new AMap.Marker();
marker.$$$id = m._idCounter++;
}else{
marker = m._pool.pop();
}
m._outPool[marker.$$$id] = marker;
return marker;
},
//归还所有
rebackAll(stepCallback){
var m = this;
_.each((ins,$id)=>{
debugger;
if(stepCallback) {
stepCallback(ins);
}
m.reback(ins);
})
}
};