标签:span ack asto 面向对象 his 注意 style ddd i++
1 function Stack() { 2 this.dataStore = []; 3 this.top = 0; //指向栈顶的位置 4 this.push = push; 5 this.pop = pop; 6 this.peek = peek; 7 this.clear = clear; 8 this.length = length; 9 10 function push(element) { 11 this.dataStore[this.top++] = element; //先赋值后++ 12 } 13 14 function peek() { 15 return this.dataStore[this.top - 1]; 16 } 17 18 function pop() { 19 return this.dataStore[--this.top]; //先--运算 20 } 21 22 function clear() { 23 this.top = 0; 24 } 25 26 function length() { 27 return this.top; 28 } 29 } 30 31 var s = new Stack(); 32 s.push("David"); 33 s.push("Raymond"); 34 s.push("Bryan"); 35 console.log(s); 36 console.log("length: " + s.length());
标签:span ack asto 面向对象 his 注意 style ddd i++
原文地址:http://www.cnblogs.com/dongruiha/p/6307318.html