- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2015 04:14 AM
i have a script include that has 3 functions. lets call them function a, b and c
from function a i want to call function b OR c depending on a variable given by the businessrule thats calling function a.
the variable has the function b or c as value.
is it possible to call the function like this inside function a, with a variable? I know I can code around it with a IF, but i have 20 more functions that can be called. so i would get 20 IF statements.
a : function(functioName) {
do something...
var callFunction = functionName+'()'; // callFunction = 'b()' or 'c()'
var value = this.callFunction; // this will go to the function b or c
},
b : function {
do something
},
c : function {
do something else
}
thank you in advance
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2015 06:04 AM
I found a solution.
i have to use the javascript funtion eval() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
this way i can execute a string as javascript!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2015 04:20 AM
You would make those private functions, no? So, _b and _c. I think you should be able to do something like this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2015 04:26 AM
well, the way I have written it in my example I cant get it to access the function.
when I change this.callFunction to this.b() it does go to function b
does making the functions private do any difference?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2015 04:27 AM
It just makes it callable by only the current function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2015 06:04 AM
I found a solution.
i have to use the javascript funtion eval() https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
this way i can execute a string as javascript!