(1)创建继承体
-
- function Person(){
- this.name =name,
- this.age = age
- }
- Person.prototype.say() = function(){
- console.log("111",this.name)
- }
- var obj = new Person()
- obj.say()
-
(2)继承属性和原型方法
- //创建一个Student构造函数
- function Student(name,age,grade){
- //继承Person的name和age属性,call(this)是为了改变this指向,让this指向由Person变为Student
- Person.call(this,name,age)
- this.grade = grade
- }
-
-
- var obj2 = new Student('linlin',24,98)
- console.log(obj2)
- function Person(name,age){
- //Person属性
- this.name = name,
- this.age = age
- }
- Person.prototype.say = function(){
- console.log("111",this.name)
- }
-
- //创建一个Student构造函数
- function Student(name,