Empty function inside another to execute script from another file

-1

I have a file called funcoes.js and another called events.js I need the script that is written inside events.js to run inside functions.js in another function, but in the order that it is placed inside it.

ex. The function inside funcoes.js

$.fn.test = function(dados) {
  function antes(script){}
  alert(dados);
  function depois(script){}
}

script fired from events.js

$("#botao").test("teste")
antes(alert("antes");)
depois(alert("depois");)
    
asked by anonymous 15.05.2018 / 12:03

1 answer

0

If I get it right, you want a test function that gets a parameter, but it also gets 2 code snippets to run before and after processing this parameter, right?

If is this, then one way to solve it is to change its test function to get 3 parameters: the data, the script to be executed before, and the script to be executed after: / p>

$.fn.test = function(dados, scriptAntes, scriptDepois) {
  scriptAntes();
  alert(dados);
  scriptDepois();
}

To call the function, you pass the data normally, but each script must be function :

$("#botao").test("teste", 
  function() { alert("antes"); }, 
  function () { alert("depois"); })

This will first show alert with "before", then "test" will appear, and finally "after".

    
15.05.2018 / 13:59