构造函数:Student
原型对象:prototype
实例对象:stu1
三者的关系如下图所示:
①构造函数Student的prototype属性指向了原型对象prototype,原型对象prototype的constructor属性又可以指向构造函数Student
②实例对象stu1的属性__proto__指向了原型对象prototype,实例对象又可以通过原型对象的属性constructor指向构造函数
③构造函数则通过new关键字创建一个实例对象stu1
④其中
stu1.__proto__==Student.prototype
stu1.__proto__.constructor==Student.prototype.constructor
function Student(name,age){
this.name=name;
this.age=age;
this.sing=function(){
console.log('我会唱歌');
}
}
var stu1=new Student('wang',20);
console.log(stu1.__proto__);
console.log(Student.prototype);
console.log(Student.prototype.constructor);
console.log(stu1.__proto__.constructor);