var myNamespace = {
dateController: {}
};
myNamespace.dateController = function(callback) {
this.callbackfunction = callback;
try {
[this.callbackfunction]();
} catch (e) {
alert(e);
}
};
function displayDate() {
alert("displayDate");
myNamespace.dateController("displayDateFromController");
};
function displayDateFromController() {
alert("In displayDateFromController");
};
This piece of code is giving me TypeError: ["displayDateFromController"] is not a function error. What could be root cause and possible solution to this issue.
Why dateController not able to identify displayDateFromController as function.
I have tired this on http://www.w3schools.com/js/tryit.asp?filename=tryjs_events
[]. What you are actually doing is puttingthis.callbackfunctionin an array and trying to call that array as a function. 2) don't pass the functionName as a string to yourdateControllerfunction. Instead just pass the function itself:myNamespace.dateController(displayDateFromController);