javascript - Using bracket notation opposed to eval -
i have following
var module = function(){ console.log('module ran') } var somestring = 'module' [string]() //typeerror: object not function eval(somestring)() // works fine! i'm trying run module function, of course don't want use eval but, don't see why brackets isn't work.
how should written same result @ eval
bracket notation used access object properties. if that's on global scope (and if you're on browser), can use this:
window[somestring]();
Comments
Post a Comment