I have a custom ASP.Net control that has a function name to be attached inside a javascript object:
<custom:myControl runat="server" id="something" OnClientOpened="myFunc" />
I then have a state javascript object that has the string "myFunc":
state.onClientOpened // contains "myFunc"
I am binding a function to the slideUp argument like this:
// this code is inside an Object
// Simplified for clarity
$el.slideUp(200, window[state.onClientOpened]);
I have no control over what goes into the OnClientOpened property so then I tested something that wasnt in the global namespace:
var MyObject = function() {
var myFunc = function() {
doSomething();
};
return {
myFunc: myFunc
};
}();
The state.onClientOpened would now contain:
onClientOpened = "MyObject.myFunc";
This obviously breaks it. Whats the best approach for this? I'm thinking some sort of eval but I'm hoping for another approach if possible.
Eval solution:
$el.slideUp(200, eval("window." + state.onClientOpened));