javascript - javascript es6类:在同一类的另一个方法中调用一个类的方法
问题描述
我的代码是:
PRELOADER_COUNTER = 0;
class Preloader {
constructor(timeout=15000) {
PRELOADER_COUNTER++;
this.counter = PRELOADER_COUNTER;
this.timeout = timeout;
}
hide() {
if ( this.counter === PRELOADER_COUNTER ){
app.preloader.hide();
}
}
show() {
app.preloader.show();
setTimeout(
function(){
this.hide(this.counter);
}, this.timeout
);
}
}
当我在控制台中运行时:
var d = new Preloader(1000);
d.show();
我收到此错误:未捕获的 TypeError:this.hide 不是函数
我究竟做错了什么?
解决方案
推荐阅读
- php - Laravel Auth::user() always null
- json - How do I parse JSON key pair values in BigQuery?
- java - i see grey code in android studio. What is grey code mean?
- python - Docx file corrupted when adding an image with python docx
- javascript - How to save data from a planner in real time database using javascript?
- docker - docker-compose up -d send disconnect: Broken pipe
- amazon-web-services - Sync two different s3 buckets on different accounts on an ec2 instance
- python - 为什么 django 抛出完整性错误?
- jquery - 使用 jquery 将悬停标题添加到选项卡图像库
- java - 使用 Gmail Java API 更改 Gmail 中的默认签名