Skip to content

Instantly share code, notes, and snippets.

@nukisashineko
Created August 23, 2017 21:45
Show Gist options
  • Save nukisashineko/ac5776c445e4cd5c20f0d4fb020096db to your computer and use it in GitHub Desktop.
Save nukisashineko/ac5776c445e4cd5c20f0d4fb020096db to your computer and use it in GitHub Desktop.
class Bot {
constructor() {
this.memberVariable = 'aaa';
}
doSomething() {
console.log(this.memberVariable) // => undefined
// do somethings
}
// handle method 一覧
async a() {
// this.doSomething(); // => TypeError: this.doSomething is not a function
console.log(this); // => { a_func: [Function: a],b_func: [Function: b],c_func: [Function: c] }
}
b() {
}
async c() {
}
// メイン
async process(text) {
// textによって呼び出す関数を分ける。
var t = this;
const handle = {
a_func: t.a,
b_func: t.b,
c_func: t.c,
};
if (handle[text]) {
await handle[text]();
}
}
}
const bot = new Bot();
bot.process('a_func');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment