I want to call function from variable i got success but i want to call function and also pass parameters,how to do it. please let me know.
Below i have mention function which is working without parameter.
function myfunction(){
alert("hellow world");
}
var aa= "myfunction";
window[aa](); // working
function myfunction(param){
alert(param);
}
// .....?
asked Nov 5, 2014 at 13:59
Syed Daniyal Asif
7361 gold badge5 silver badges19 bronze badges
-
1@Cerbrus The answer in the question of which you marked this a duplicate is what the OP says he can do already. So while this is a very poor question (OP should have at least tried the obvious), I don't think it's a duplicate of the question that you selected, as that question (and its marked answer) do not address passing parameters.Patrick Q– Patrick Q2014年11月05日 14:12:09 +00:00Commented Nov 5, 2014 at 14:12
4 Answers 4
You can pass arguments to your function where you call window[aa]() like so:
function myfunction(text){
alert(text);
}
var aa= "myfunction";
window[aa]("Hello Again..."); // just put any arguments in the parentheses.
answered Nov 5, 2014 at 14:03
Chris
3,3281 gold badge34 silver badges40 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Just pass it in:
window[aa](param)
answered Nov 5, 2014 at 14:01
tymeJV
105k14 gold badges165 silver badges158 bronze badges
2 Comments
Cerbrus
Really? A answer instead of a close-vote?
Inspector Squirrel
He only has 48k @Cerbrus, why would you think he'd know better? :/
Can you just put the parameter between the parentheses when you call the function?
window[aa]("Hello, world");
Comments
use this:
function myfunction(param){
alert(param);
}
var aa= "myfunction";
window[aa]('mk');
answered Nov 5, 2014 at 14:06
Mukund Kumar
23.5k20 gold badges64 silver badges85 bronze badges
Comments
lang-js