Created
August 23, 2017 21:45
-
-
Save nukisashineko/ac5776c445e4cd5c20f0d4fb020096db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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