gpt4 book ai didi

javascript - 设置间隔函数不作为方法

转载 作者:行者123 更新时间:2023-11-30 20:31:14 24 4
gpt4 key购买 nike

<分区>

谁能告诉我为什么 setInterval 在此代码中不起作用。我可能遗漏了一些东西,但我不确定它是什么。我正在尝试运行方法 args.counts();

错误是:

Uncaught TypeError: this.cast is not a function at 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();

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com