I have the below code.
(function($) {
var myFunction = function(element) {
var myCallerFunction = function() {
var functionName = 'myInternalCallFunction';
myFunction[functionName]();
console.log(2);
}
var myInternalCallFunction = function() {
console.log(1);
}
myCallerFunction();
}
$.fn.myfunction = function(options) {
var func = new myFunction();
}
})(jQuery);
Inside myCallerFunction I created a variable which holds the function name I want to call. I then try to call it, however it returns that it can't find the function. It finds the namespace myFunction okay as if I change:
myFunction[functionName]();
to
myFunctionTest[functionName]();
It returns it can't find "myFunctionTest" instead of not being able to find "myInterncalCallFunction".
Any ideas why it can't find the function?
myInternalCallFunctiontoo late. It simply doesn't exist yet (and isn't a property of myFunction)myInternalCallFunctionis not a property ofmyFunctionbtw.myFunction[functionName]is actuallyundefined.. did you read my comment?myFunction[functionName]functionNameis being called as a property of an Object instead of a parameter of the function for what I can see. Have you tried wrapping everything up in an object and calling the properties?