1. <script>
    2. function Stack(){
    3. this.items =[];
    4. }
    5. /*
    6. 入栈 push
    7. 出栈 pop
    8. peek 获取栈顶
    9. isEmpty 判断栈是否为空
    10. size 可以看栈中是否有多少个只
    11. */
    12. Stack.prototype.push = function(val){
    13. this.items.push(val);
    14. }
    15. Stack.prototype.pop = function(){
    16. var res = this.items.pop();
    17. return res;
    18. }
    19. Stack.prototype.peek = function(){
    20. return this.items[this.items.length-1]
    21. }
    22. var s =new Stack();
    23. s.push(2);
    24. s.push(3);
    25. console.log(s.items);
    26. //console.log(s.pop())
    27. console.log(s.peek())
    28. </script>
    1. <script>
    2. /*
    3. Members
    4. name
    5. age
    6. sex
    7. 在Members原型上定义sayNamae方法 console.log(this.name)
    8. 实例化自己和同桌
    9. 08里面写
    10. */
    11. function Student(name,age,sex){
    12. this.name = name;
    13. this.age = age;
    14. this.sex = sex;
    15. }
    16. Student.prototype.sayName = function(){
    17. console.log(this.name)
    18. }
    19. Student.prototype.saySkill = function(){
    20. console.log(this.age)
    21. }
    22. Student.prototype.saysex = function(){
    23. console.log(this.sex)
    24. }
    25. var p = new Student("韩磊",21,"男")
    26. console.log(p)
    27. p.sayName();
    28. p.saySkill();
    29. p.saysex();
    30. var g = new Student("高云锋",20,"男")
    31. console.log(g);
    32. g.sayName();
    33. g.saySkill();
    34. g.saysex();
    35. </script>