class Hoge {
constructor(){
this.arr = [
"hoge1",
"hoge2",
"hoge3"
]
}
hoge1() { console.log(1) }
hoge2() { console.log("piyo") }
hoge3() { console.log(100) }
hoge(){
var that = this
this.arr.forEach(function(v, i, a){
that[v]();
})
}
}
this を that に入れているけど..他に方法ありますでしょうか..。
> h = new Hoge()
# Hoge { arr: [ 'hoge1', 'hoge2', 'hoge3' ] }
> h.hoge()
# 1
# piyo
# 100
# undefined