SOURCE

function Stack() {}

Stack.prototype.dataStroe = [];
Stack.prototype.top = 0;
Stack.prototype.push = function(element) {
    this.dataStroe[this.top++] = element
}
Stack.prototype.pop = function() {
    return this.dataStroe[--this.top]
}
Stack.prototype.peek = function() {
    if (this.top > 0) {
        return this.dataStroe[this.top - 1]
    } else {
        return 'empty'
    }
}
Stack.prototype.length = function() {
    return this.top;
}
Stack.prototype.clear = function() {
    this.dataStroe = [];
    this.top = 0;
}

let stack = new Stack();

stack.push('cjsong')
stack.push('cjsong2')
stack.pop()
console.log(stack.dataStroe)
console.log(stack.length())


console 命令行工具 X clear

                    
>
console