I'm new to JS and have I made this snippet for practicing. Because I have no idea for JS conventions, I want some advice about that.
function Queue() {
this.list = new Array();
this.pop = function() {
return this.list.pop()
};
this.push = function(el) {
this.list.unshift(el);
};
this.size = function() {
return this.list.length;
};
this.isEmpty = function() {
return this.size() == 0;
}
this.print = function() {
var res = '(';
for (var i = 0; i < this.list.length-1; i++) {
res += this.list[i] + ',';
}
res += this.list[this.list.length-1] + ')<br/>';
document.write(res);
}
this.front = function() {
return this.list[0];
}
this.back = function() {
return this.list[this.list.length-1];
}
}
/* test code */
var myQueue = new Queue();
myQueue.push(1);
myQueue.print();
myQueue.push(2);
myQueue.print();
myQueue.push(3);
myQueue.print();
myQueue.push(4);
myQueue.print();
myQueue.push(5);
myQueue.print();
myQueue.pop();
myQueue.print();
myQueue.pop();
myQueue.print();
myQueue.pop();
myQueue.print();
myQueue.pop();
myQueue.print();
myQueue.pop();