Javascript 如何列出类方法的某些子集并对其进行操作
我有一个es6类,上面有一些方法。这个。OnGame,我必须将它与一些其他代码粘合在一起: 我如何简化这段代码:Javascript 如何列出类方法的某些子集并对其进行操作,javascript,ecmascript-6,Javascript,Ecmascript 6,我有一个es6类,上面有一些方法。这个。OnGame,我必须将它与一些其他代码粘合在一起: 我如何简化这段代码: class Gluer { glueBaby() { this.addSomeGlue('method1'); this.addSomeGlue('method2'); this.addSomeGlue('method3'); this.addSomeGlue('method4'); this.addSomeGlue('metho
class Gluer {
glueBaby() {
this.addSomeGlue('method1');
this.addSomeGlue('method2');
this.addSomeGlue('method3');
this.addSomeGlue('method4');
this.addSomeGlue('method5');
this.addSomeGlue('method6');
}
addSomeGlue(fn) {
var game = this.game;
game.client[fn] = this.OnGame[fn].bind(this.OnGame);
}
}
我需要一些干代码,以添加一些与正则表达式匹配的函数,从this.OnGame到game.client。这段代码有什么问题吗?你到底想要什么?我想去掉这种胶水,让它自动化,但可能不值得这么做。你想把OnGame中的所有功能都添加到游戏中。客户端?一些方法,可能需要一个正则表达式@请在问题中包括所有这些信息,以及一个具有预期结果的示例类。