tonelm54
asked on
Run variable as a function
Im writing my own plugin, and want to be able to run some user-code.
So to simply things, Ive just written a simple POC:-
I have been looking at using the eval function, but have lots of forums saying dont use it, but cant see an alternative.
Anyone available to point me in the right direction of fixing my code to run the function as a variable?
Thank you in advance.
So to simply things, Ive just written a simple POC:-
function tcDialog() {
var onCloseFunction = function () { alert('hi'); };
function onClose($tmpFunction) {
onCloseFunction = $tmpFunction;
}
function runMe() {
onCloseFunction();
}
}
$(document).ready(function () {
var viewJob = new tcDialog();
viewJob.onClose(function () { alert ('hi2'); });
viewJob.runMe();
});
http://jsfiddle.net/HbTpQ/I have been looking at using the eval function, but have lots of forums saying dont use it, but cant see an alternative.
Anyone available to point me in the right direction of fixing my code to run the function as a variable?
Thank you in advance.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you shouldn't use eval. What Randy has provided will work for you.