How can I reference a non-global function with window[functionName]?
<p>I'm making something like a framework for JS. I want the users to be able to add functions to a specific action, just like in wordpress plugins:</p>

<pre><code>add_action("wp_head", "functionName");
</code></pre>

<p>I looked at other questions, and the most appreciated answer was</p>

<pre><code>window['functionName']
</code></pre>

<p>But how do I do it when the function "functionName" is <strong>not global</strong>, but sits within $(document).ready({}); for example? It throws an error Uncaught TypeError: Cannot call method 'call' of undefined</p>

<p>There is one more option, that is to pass the user's function as an argument to add_action (if we suppose that my function will be named add_action as well):</p>

<pre><code>add_action("some_event", functionName);
// in the framework's JS file:
function add_action(event, fn) {
    fn();
}
</code></pre>

<p>But I have a hunch that this will be inefficient as hell and a wrong way to do it.</p>
