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

This give error. how to call test function?

asked Apr 4, 2013 at 6:22
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();
answered Apr 4, 2013 at 6:23
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.