gpt4 book ai didi

javascript - 如何根据状态显示 Console.log?

转载 作者:行者123 更新时间:2023-12-03 06:35:49 25 4
gpt4 key购买 nike

所以我已经进入了两个不同的状态。然后对于每个状态我创建了一个函数,每个函数打印不同的控制台消息。目前我能做的是,在实例化我的类之后,我可以调用任一方法或两者来手动打印其控制台消息。但是,如何根据“就绪”或“保存成功”状态打印控制台消息呢?我的代码如下。

'use strict';

class AnnServicePlugin {
constructor(learnosity) {
this._learnosity = learnosity;

this._learnosity.on('ready', () => this._learnosityReady());
this._learnosity.on('saveSuccess', () => this._learnositySuccess());
}

_learnosityReady() {
console.log('Plugin Ready')
}

_learnositySuccess() {
console.log('Plugin Success');
}
}

let annServicePlugin = new AnnServicePlugin(learnosity);
annServicePlugin._learnosityReady();

module.exports = AnnServicePlugin;

提前致谢:)

最佳答案

这样的东西行不通吗?

'use strict';

class AnnServicePlugin {
constructor(learnosity) {
this._learnosity = learnosity;

this._learnosity.on('ready', () => this._learnosityReady());
this._learnosity.on('saveSuccess', () => this._learnositySuccess());
}

_learnosityReady() {
this._state = 'ready'
}

_learnositySuccess() {
this._state = 'success'
}

_learnosityPrint() {
if (this._state == 'ready') {
console.log('Plugin Ready')
} else if (this._state == 'success') {
console.log('Plugin Success')
}
}
}

let annServicePlugin = new AnnServicePlugin(learnosity);
annServicePlugin._learnosityPrint();

module.exports = AnnServicePlugin;

关于javascript - 如何根据状态显示 Console.log?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38219886/

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