LoginSignup
2
3

More than 5 years have passed since last update.

JS 関数を動的に呼び出す

Posted at

JS学びたてで個人的にいいなと思ったのでメモ

example.js

var selectFunc = new Array();

selectFunc.hoge = function(){
    console.log("hoge");
}

selectFunc.foo = function(){
    console.log("foo");
}

var name = ["hoge","foo"];

name.forEach(function(res){
    selectFunc[res];
})

こんな感じの事が出来る。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3