You know the Requirejs ? http://requirejs.org/
Requirejs is a Javascript and module file loader. It is a javascript library.
Download into http://requirejs.org/docs/download.html#requirejs
or refer to your html in CDN //cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.min.js
With Requirejs you inform that certain portion of your javascript code requires, that is, you need another javascript library to be loaded.
Example (adapting from http://requirejs.org/docs/start.html) :
Let’s say your site has this structure :
project-directory/
--project.html
--scripts/
----cadastro.js
----exibirMensagem.js
----require.min.js (faça o download em http://requirejs.org/docs/release/2.1.14/minified/require.js )
So in your HTML do something like :
<!DOCTYPE html>
<html>
<head>
<title>My Sample Project</title>
<!-- O atributo data-main diz para o require.js carregar
scripts/cadastro.js depois que o require.js seja carregado. -->
<script data-main="scripts/cadastro" src="scripts/require.js"></script>
</head>
<body>
<h1>My Sample Project</h1>
</body>
</html>
Finally within your.js register you do something like this :
require(["exibirMensagem"], function(exibirMensagem) {
if (nome == ""){ exibirModal(); }
//Essa função será executada quando exibirMensagem.js for carregado.
//Se exibirMensagem.js usar o método define() (mais detalhes em http://requirejs.org/docs/api.html#define ), então essa função só será disparada quando todos os módulos definidos forem carregados.
});
I hope it helps.
possible duplicate of How to call Javascript functions in another Javascript
– Caputo
If none of the solutions worked, and if your question is different from @Caputo’s, you need to provide more information, possibly the source code.
– Rui Pimentel
@user13545 add the source code of the two files
– melkysalem