Good day, the following question arose, let's say we have a javascript code like:

// какоето пространство имен... var myNameSpace = { someFunc: function() { // какой-то код... } }; 

And javascript type code

 // на вход получаем строковые значения var nameSpaceName = 'myNameSpace'; // имя пространства var nameSpaceFuncName = 'someFunc'; // и имя функции // как вызвать nameSpaceName.nameSpaceFuncName()? // на ум приходит только что-то очень страшное типа eval(nameSpaceName + '.' + nameSpaceFuncName + '()'); 

    1 answer 1

    It can be like this, but only if the "namespace" is defined in the context of a window (i.e. "globally")

     window[nameSpaceName][nameSpaceFuncName]() 
    • Yes, this is it, thanks - I didn’t think =) I really need a node, but nothing changes much there: process [nameSpaceName] [nameSpaceFuncName] (); the fact that space should be global is natural, although if it is “publicly” and not globally big, changing window (process) to parentObjectName will not make up - Zowie