I am having SetUpTest() method, function name will be generated on-load of script by fetching window object.
testShieldVal.js_name is variable,
testShieldVal = window.testObject || {};
SetUpTest = testShieldVal.js_name+"SetUp";
function SetUpTest() {
new atoShieldVal.js_name.OnloadCallback(grecaptcha);
}
How can I define this function with dynamic name efficiently?
If I understand your question correctly, you are looking to define a function with a dynamic name.
In that case you should add the method to the
windowobject usingwindow[functionName] = function() { ... }This results in:
When
window.testObject.js_nameis 'Demo' then Your function can then be called viaDemoSetUp(). This will automatically look in thewindowobject for a method with that name.