【发布时间】:2018-10-23 04:01:27
【问题描述】:
谁能告诉我为什么setInterval 在这段代码中不起作用。我可能遗漏了一些东西,我不确定它是什么。我正在尝试运行方法args.counts();
错误是:
未捕获的类型错误:this.cast 不是 Caste.log 中的函数 (prototype.js:17)
function Caste(){
this.name = 'James';
this.surname = 'Penn';
this.age = 38;
this.one = document.getElementById('one');
this.two = document.getElementById('two');
this.cast = function(){
return this.age;
}
// ------------------------
this.log = function(){
console.log(this.cast());
}
// ------------------------
this.display = function(){
this.one.innerHTML = this.age;
}
this.counts = function(){
(setInterval(this.log, 2000));
}
}
// ----------------------
let args = new Caste();
args.counts();
【问题讨论】:
-
昆汀,你能给我看看副本吗
-
Kingsley Ajebon 他刚刚做了......使用欺骗链接(顺便说一句,即使问题不一样,它也可以关闭,但答案解决了两者)
-
好的。见过。在我回复之前,页面没有完全加载。谢谢。
标签: javascript oop object methods constructor