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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -