Wednesday, 14 August 2013

How do I call a dynamically-named method with for in Javascript

How do I call a dynamically-named method with for in Javascript

I have 2 JavaScript functions that dynamically-named..
function a1(){
//some codes
}
function a2(){
//some codes
}
function a3(){
//some codes
}
these functions above generated by PHP for sure..
<?php
for($i = 1; $i <= $load_period->count; $i++){
?>
<script type="text/javascript">
function a<?php echo $i;?>(){
//javascript fucntions
}
</script>
<?php
}
?>
now i have to call both of these functions with for..
for(var i= 0; i <= 3; i++){
// here the solution code ..
// doesn't work >> a+i+();
}
NB 1 : it's doesnt work with "a+i+();" .
NB 2 : i dont want to use "EVAL" syntax
thanks for any solution..

No comments:

Post a Comment