lundi 2 février 2015

Creating temporal functions with dynamically generated names in jQuery


I have an external javascript file which is loaded dynamically, and it has an oncomplete= variable, which increases its value each time that it is called. For example:



  • First time: external.js?oncomplete=sayHello1

  • Second time: external.js?oncomplete=sayHello2

  • Third time: external.js?oncomplete=sayHello3


Because of that I need to dynamically create functions to execute the oncomplete= callback each time. That means, that I need to create functions with these names:



  • sayHello1();

  • sayHello2();

  • ...etc


This is my current code, which creates a specific name function:



var sayHello = function (){
console.log('hello');
};
sayHello1();


The question is: How can I create temporal functions with dynamically generated names in jQuery?





Aucun commentaire:

Enregistrer un commentaire