Created
August 23, 2017 22:04
-
-
Save nukisashineko/2d6e22c89b3e4218bc47a6853da030e8 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
const Bot = function () { | |
this.memberVariable = 'aaa'; | |
}; | |
Bot.prototype.doSomething = function () { | |
console.log(this.memberVariable); | |
}; | |
Bot.prototype.a = async function () { | |
// this.doSomething(); // => this.doSomething is not a function | |
console.log(this); // => { a_func: [Function], b_func: [Function], c_func: [Function] } | |
}; | |
Bot.prototype.b = function () { | |
}; | |
Bot.prototype.c = async function () { | |
}; | |
Bot.prototype.process = async function (text) { | |
// textによって呼び出す関数を分ける。 | |
const 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