以下结构
function SomeObject() {}
SomeObject.prototype.repeatWhat = function() {
setInterval(this.what, 1);
}
SomeObject.prototype.what = function() {
console.log("what?");
}
在控制台中只生成一个"what?"
,为什么不能永久运行?
我称之为
var someInstance = new SomeObject();
someInstance.what();
答案 0 :(得分:2)
您没有在代码中调用repeatWhat
var someInstance = new SomeObject();
someInstance.what();
someInstance.repeatWhat(); //I've added this