0
var VariableName = {
    Test: function () {
        alert("test");
    }
};
window["VariableName.Test"]();

This give error. how to call test function?

1
  • 1
    Assuming you declared VariableName in global scope, window['VariableName']['Test']() or window.VariableName.Test(). Commented Apr 4, 2013 at 6:23

1 Answer 1

2

If you're trying to use strings for the object and property names, you can do it like this:

window["VariableName"]["Test"]();

But, if you already know the names, it can just be this:

window.VariableName.Test();

or this if only the Test name is know ahead of time:

window["VariableName"].Test();
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.