Blog on software engineering
How to call a JavaScript function by string name.

How to call a JavaScript function by string name.

An excellent answer to this question can be found at:

I knew you could call a JavaScript function by it’s string name, by using window[‘functionName’], but this does not work for namespace functions.

When you want to call a namespace function by it’s string name you should use the namespace as context, instead of the window object.

<!DOCTYPE html>
    <title>General testpage.</title>
    <script src="/Scripts/Kendo/jquery.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var MyApp = {};
        MyApp.Navigation = {};
        MyApp.Navigation.refreshDataSources = function ()
            alert("Alert from refreshDataSources.");

        // Dynamically calling namespace function by string name:

        // Dynamically get namespace part and calling a function in this namespace.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.