代码如下:
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);
部分,为什么要用闭包?
慕运维8079593
相关分类