demo
<script>/* 学生类,name,age,skillsayName*//*1、构造函数必须通过new关键字才可以调用2、this指向实例化的对象*/function Student(name,age,skill){this.name = name;this.age = age;this.skill = skill;}Student.prototype.sayName = function(){console.log(this.name)}Student.prototype.saySkill = function(){console.log(this.skill)}var p = new Student("李四",18,"编程");console.log(p)p.sayName();p.saySkill()/*类对象原型*/</script>
demo2
<script>function Stack(){this.items = [];}/*入栈 push出栈 poppeek 获取栈顶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.peek())</script>
