当前位置: 代码迷 >> JavaScript >> js自持队列――FIFO
  详细解决方案

js自持队列――FIFO

热度:316   发布时间:2012-11-23 22:54:33.0
js自制队列――FIFO
//js's queue by yj
function js_queue(){
	this.head = 0;
	this.arr = new Array();
}
js_queue.prototype.put = function(obj){
	this.arr[this.arr.length] = obj;
}
js_queue.prototype.get = function(){
	if(this.head == this.arr.length) return null;
	var return_string = this.arr[this.head];
	this.head += 1;
	return return_string;
}

var q = new js_queue();
q.put('s1');
q.put('s2');
q.put('s3');
alert(q.get());
alert(q.get());
alert(q.get());
alert(q.get());