After the issue of the question that Bacco asked was that I realized that I had misunderstood. I went to the title and did not see that one function is inside the other, because the indentation is not without pattern. In this case you do not need to do anything, just access the variable, the code already asked would already work without changes, just test. An internal function accesses all variables of the outermost scope, so buscarTarefasAtrasadas()
"sees" the variables of buscarTarefasAtrasadas()
.
function criarDataset(field, constraint, sorFields) {
totalTarefasAtrasadas = buscarTarefasAtrasadas();
function buscarTarefasAtrasadas() {
usuario = constraint;
console.log(usuario);
return 6;
}
}
criarDataset("a", "b", "c");
I put in the Github for future reference.
Now, if the problem is having two separate functions, you can also pass it as a parameter to the other function. Functions should always communicate through parameters and return.
function criarDataset(field, constraint, sorFields) {
totalTarefasAtrasadas = buscarTarefasAtrasadas(constraint);
}
function buscarTarefasAtrasadas(constraint) {
usuario = constraint;
console.log(usuario);
return 6;
}
criarDataset("a", "b", "c");
There are other ways to solve this case, but it’s a scam and I won’t pass.