js 자체 제작 대기 열 -- FIFO

640 단어 prototype

//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());

좋은 웹페이지 즐겨찾기