原型链
1.首选写几个函数
// 构造函数
function Person(name, age, job) {
this.name = name
this.age = age
this.job = job
this.sayName = function () {
alert(this.name)
}
}
console.log(Person)
var person1 = new Person('zhaojie', 55, 'leader');
var person2 = new Person('zhou', 20, 'player');
console.log(person1)
console.log(person2)
console.log(person1.constructor == Person);
console.log(person2.constructor == Person);
// 原型对象
function Person() {
Person.prototype.name = 'zhouyi'
Person.prototype.age = '26'
Person.prototype.job = 'engineer'
Person.prototype.sayName = function () {
alert(this.name)
}
}
let person6=new Person();
person6.sayName()
let person7=new Person();
person7.sayName()
console.log(person6.sayName == person7.sayName)
console.log(Person.prototype.constructor == Person)
2.
实例的_proto_属性指向原型对象
原型对象的_proto属性指向原型对象 构成原型链
原型对象的constructor属性指向构造函数
构造函数的prototype属性指向原型对象
构造函数通过new实例化实例