代碼如下:
function Dog() {
this.wow = function() {
console.log("Wow");
}
this.yelp = function() {
this.wow();
}
}
function MadDog(){
}
MadDog.prototype=new Dog();
MadDog.prototype.yelp=function(){
var self=this;
setInterval(function(){
self.wow();
},2000);
}
var test=new MadDog();
test.yelp();
就是:
var self=this;
setInterval(function(){
self.wow();
},2000);
部分,為什么要用閉包?
請問setInterval里的代碼為什么要用閉包?
手掌心
2018-12-07 10:48:15