开发者

Putting a variable into name of function javascript

开发者 https://www.devze.com 2023-02-08 21:42 出处:网络
I want to do the following: var table = new google.visualization.XXXXX(document.getElementById(divId));

I want to do the following:

var table = new google.visualization.XXXXX(document.getElementById(divId));

where the X's represent a vari开发者_运维百科able that is set previously.

Just so you know, I'm using Google visualizations here, but I don't think that is necessarily relevant to this question.


Use square bracket notation.

var XXXXX = "someString";
var table = new google.visualization[XXXXX](document.getElementById(divId));


Pretty simple:

var table = new google.visualization[XXXXX](document.getElementById(divId));

Should do the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消