0

I'm updating an old project to now use requirejs. I have a method which dynamically calls other methods. Before, my App was registered in the global scope so the below code worked. Now that my App is now a module, window['App'] is undefined.

How can I check if an unknown method exists on my App module from within the module itself?

var App = {
    run: function(name, args) {
        if(typeof window['App'][name] == 'function') {
            window['App'][name].apply(undefined, args);
        }
    }
}

1 Answer 1

1

Figured it out, I now feel silly for not trying this sooner.

var App = {
    run: function(name, args) {
        if(typeof this[name] == 'function') {
            this[name].apply(undefined, args);
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.