<script>
function Stack(){
this.items =[];
}
/*
入栈 push
出栈 pop
peek 获取栈顶
isEmpty 判断栈是否为空
size 可以看栈中是否有多少个只
*/
Stack.prototype.push = function(val){
this.items.push(val);
}
Stack.prototype.pop = function(){
var res = this.items.pop();
return res;
}
Stack.prototype.peek = function(){
return this.items[this.items.length-1]
}
var s =new Stack();
s.push(2);
s.push(3);
console.log(s.items);
//console.log(s.pop())
console.log(s.peek())
</script>
<script>
/*
Members
name
age
sex
在Members原型上定义sayNamae方法 console.log(this.name)
实例化自己和同桌
08里面写
*/
function Student(name,age,sex){
this.name = name;
this.age = age;
this.sex = sex;
}
Student.prototype.sayName = function(){
console.log(this.name)
}
Student.prototype.saySkill = function(){
console.log(this.age)
}
Student.prototype.saysex = function(){
console.log(this.sex)
}
var p = new Student("韩磊",21,"男")
console.log(p)
p.sayName();
p.saySkill();
p.saysex();
var g = new Student("高云锋",20,"男")
console.log(g);
g.sayName();
g.saySkill();
g.saysex();
</script>