Skip to content

Instantly share code, notes, and snippets.

@urstory
Created December 3, 2015 05:42
Show Gist options
  • Save urstory/e9a9eaf3c4765eb01be6 to your computer and use it in GitHub Desktop.
Save urstory/e9a9eaf3c4765eb01be6 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script>
function Queue(){
this.data = [];
this.add = function(d){
this.data.push(d);
};
this.get = function(){
var d = this.data[0];
// 0번째 위치한 1건 삭제.
this.data.splice(0,1);
return d;
};
this.size = function(){
return this.data.length;
};
}
var queue = new Queue();
queue.add('hello');
alert(queue.size());
queue.add('hi');
alert(queue.size());
queue.add('javascript');
alert(queue.size());
alert(queue.get());
alert(queue.size());
alert(queue.get());
alert(queue.size());
alert(queue.get());
alert(queue.size());
alert(queue.get());
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment