/**
* apply,call和bind函数都是会改变这个函数内部的this指向,但是略有差别
* apply中除了传入this的指向之外还要传入一个数组
* call中除了传入this的指向之外还要传入这个函数应该传入的对象
* bind中只需要传入this的指向,但是这个函数只是引用,复制了一份,并不会调用
* */
function ShowRandom() {
this.number = parseInt(Math.random() * 10 + 1)
}
ShowRandom.prototype.show1 = function () {
//setInterval所需要传入的函数里面的内容中this的指向是window,但是在引用函数的时候this的指向还是外面的this指向
//所以说在这个上面这个this.show2.bind(this)中的this是ShowRandom的实例对象,但是这个函数内部的this指向是window
//然后我们再改变这个函数内部中的指向,让它的的指向是实例对象
window.setInterval(this.show2.bind(this), 1000)
}
ShowRandom.prototype.show2 = function () {
console.log(this.number);
}
new ShowRandom().show1()