function Stack() { this.dataStore = []; // 保存栈内元素 this.top = 0; // 栈指针 this.push = push; this.pop = pop; this.peek = peek; this.clear = clear; this.length = stackLength;}// 入栈function push(element) { this.dataStore[this.top++] = element;}// 出栈function pop() { return this.dataStore[--this.top];}// 返回栈顶元素function peek() { return this.dataStore[this.top - 1];}// 清栈function clear() { this.top = 0;}function stackLength() { return this.top;}var s = new Stack();s.push('一');s.push('二');s.push('三');s.push('四');console.log('len', s.length());console.log(s.pop())console.log(s.pop())console.log(s.length())