var FlyWeight = function() {
var created = [];
function create() {
var dom = document.createElement('div');
document.getElementById('container').appendChild(dom);
created.push(dom);
return dom;
}
return {
getDiv : function() {
if (created.length > 5) {
var div = created.shift();
created.push(div);
return div;
} else {
return create();
}
}
}
}();
var paper = 0,num = 5,len = article.length;
for(var i = 0; i < 5; i++) {
if (article[i]) {
FlyWeight.getDiv().innerHTML = article[i];
}
}
document.getElementById('next_page').onclick = function() {
if (article.length < 5)
return;
var n = ++paper * num % len,j = 0;
}
避免对象间拥有相同内容造成多余开销