<script>
function Star(name,age){
this.name=name;
this.age=age;
}
Star.prototype.sing=function(){
console.log("唱歌")
}
console.log(Star.prototype);
console.log(Star.prototype.constructor);
var ldh=new Star('刘德华',18);
var zxy=new Star('张学友',19);
ldh.sing();
ldh.__proto__.sing=function(){
console.log("这是修改后的唱歌");
}
ldh.sing();
// 实例对象.hasOwnProperty('属性')可以判断属性是自有的还是继承来的
console.log(ldh.hasOwnProperty('name'));//true
console.log(ldh.hasOwnProperty('sing'));//false
//官方推荐的 使用 a instanceof b构造函数 判断a是否是通过b构造函数构造出来的
console.log(ldh instanceof Star );//true
//a.isPrototypeOf(b)判断a是否存在b的原型链中
console.log(Star.prototype.isPrototypeOf(ldh));//true
console.log(Object.prototype.isPrototypeOf(ldh));//true
console.log(Object.prototype.isPrototypeOf(Star.prototype));//true
console.log(Star.prototype.isPrototypeOf(Star.prototype));//false
// 自身不能说存在自身原型链中
</script>
原型链
当从一个对象那里调取属性或者方法的时候,如果该对象自身不存在这样的属性或者方法,
就会去关联的prototype那里寻找。如果prototype没有,就会去prototype关联的prototype那里寻找
直到prototype…prototype…为null的时候,从而形成了原型链(根本上来说就是继承的关系)