[英]setInterval with an object method only running once
The following structure 以下结构
function SomeObject() {}
SomeObject.prototype.repeatWhat = function() {
setInterval(this.what, 1);
}
SomeObject.prototype.what = function() {
console.log("what?");
}
Produces only a single "what?"
只产生一个"what?"
in the console, why isn't it just running perpetually? 在控制台中,为什么不是永久运行?
I call it like so 我称之为
var someInstance = new SomeObject();
someInstance.what();
You aren't calling repeatWhat
in your code 您没有在代码中调用repeatWhat
var someInstance = new SomeObject();
someInstance.what();
someInstance.repeatWhat(); //I've added this
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.