I've found here is a good explication of the difference between run-time functions and parse-time ones. Bit what i'm trying to do is something like this
var funtionName = 'functionInside';
var start = function(){
var a = function(){doSomething();}
return {functionInside:a}
};
And i want to call function 'functionInside' with the variable, something like
start.window[funtionName]()
Thanks in advance!
asked Nov 13, 2014 at 18:34
Braian Mellor
1,9543 gold badges31 silver badges51 bronze badges
1 Answer 1
There are couple of ways to do that depending on what you need.
Here are two examples:
var start = {
functionInside : function(){
doSomething();
}
};
start[funtionName](); //different ways to invoke
start.functionInside();
Here's another approach:
var start = function() {
this.functionInside = function() {doSomething();}
}
var s = new start();
s[funtionName](); //different ways to invoke
s.functionInside();
Sign up to request clarification or add additional context in comments.
2 Comments
Braian Mellor
and if i want to know which function was call??
Benny Lin
add conole.log or alerts in different areas so you can see. Or in chrome, add stops so you can trace the code.
lang-js