Is it possible to insert new actions inside the scope of a function from outside? For example:
       function main(){
           //I want to insert in here new action to perform
       }
       var dosomething = function() { 
             console.log("I want to be inside the main");
       }
       main();
How do I make the function main permanently execute the function dosomething?
And after that, how can I take out the function dosomething from the main?
 The concept is more or less this:
    function main(){
           //I want to insert in here new actions to perform
    }
    var dosomething = function() { 
             console.log("I want to be inside the main");
    }
   *insert dosomething in main*
   //This is how it should look now the function main:
   function main(){
          dosomething();
   }
   *erase dosomething from main*
   //The function main come back to be empty:
   function main(){
   }
The only solution I found is to make the function main execute all the functions inside an array and use this array to insert/take-out functions from outside. Is there any better solution?
 
    