var VariableName = {
Test: function () {
alert("test");
}
};
window["VariableName.Test"]();
This give error. how to call test function?
1 Answer 1
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
jfriend00
711k104 gold badges1.1k silver badges1k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
VariableNamein global scope,window['VariableName']['Test']()orwindow.VariableName.Test().