/**
* 原型对象中this的指向
*
* 1. 在构造函数中 this指向的事对象实例 例如 yy
*/
function Star(name, age) {
// 构造函数中,this指向的是实例对象 yy
this.name = name;
this.age = age;
}
// 在原型对象函数中的this指向的也是 实例对象yy
var $this;
Star.prototype.sing = function() {
console.log('唱歌');
$this = this;
}
var yy = new Star('yy',22);
yy.sing();// 调用了这个方法 才知道this指向的是谁
console.log($this === yy); // true