필자는 DRY 프로그래밍을 따르려고 노력해 왔고 부모 코드에서 도움이되는 메서드를 중첩하려고 시도했습니다. 아무것도 다시 가져 오지 않았다 class.chat.method()
를 호출 을 예상대로ES6 클래스의 중첩 방법은 무엇입니까?
chat() {
client.on("chat", (channel, user, message, self) => {
method() {
// code here
}
method() {
// code here
{
}
}
그러나 그것은 작동하지 않았다. 내가 정말로 도움이 필요한 것은 내가 사용하는 모든 방법을 client.on("chat", callback())
라고 부르는 내 드라이 프로그램을 제거하는 것입니다. 호기심이 막을 수 있는지 그리고 그 안에 호출 된 메소드가있는 단편이 하나 있습니다.
FULL CODE :
watchFor(command, res, sendersName, prefix) {
this.client.on("chat", (channel, user, message, self) => {
console.log(this._showSendersName.whitelistedCommands);
if (message == this.prefix + command || message == prefix + command) {
return this.client.say(channel, res);
}
});
}
modOnly(command, res) {
this.client.on("chat", (channel, user, message, self) => {
if (this._showSendersName == false) {
if (self) return
}
if (message == this.modPrefix + command && user.mod || message == this.prefix + command && user.mod) {
return this.client.say(channel, res);
}
});
}
broadcasterOnly(command, res) {
this.client.on("chat", (channel, user, message, self) => {
if (this._showSendersName == false) {
if (self) return
}
if (message == this.prefix + command && user.badges.broadcaster == 1) {
return this.client.say(channel, res);
}
});
}
이벤트를 처리하는 '클라이언트'가 아닌 다른 객체에 넣으려는 것 같습니까? – Bergi
음, 정확히 무엇을 의미합니까? –
나는 이벤트를 다루기 위해 채팅을 원한다. 그러나 클래스에 새로운 메소드를 쓸 때마다 매번 채팅 이벤트를 호출하는 대신 하나의 채팅 이벤트 만 필요하다. –