There is such a structure of JavaScript code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> initSky() { function imitate() { } function tracker() { } } </script> <script> $('#btn').click(function() { for (j; j <= finDay; j++) { imitate(); }; }); </script> 

How to call the imitate () function without changing its location?

  • one
    No way, besides, you have a syntax error when declaring the function initSky - the code above does not work at all - Grundy
  • everything works for me, I just removed the unnecessary, and brought the code structure to make it clear where the function is called from. all the code to fill did not see the point. - Alexander Belyakov
  • one
    I moved your code to a snippet, and you can make sure that there is a syntax error in it - Grundy

1 answer 1

Unless to make functions through global variables:

 <script> function initSky() { imitate = function() { // пробрасываем функции в глобальную область видимости } tracker = function() { } } initSky(); </script> <script> $('#btn').click(function() { for (j; j <= finDay; j++) { imitate(); }; }); </script>