Putting a variable into name of function javascript
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.
精彩评论