If you want to call the function, of course it works, but the syntax wouldn’t be this, it would be like this:
if (a > 1) {
Save();
} else {
NoSave();
}
But if you want to define functions conditionally, then it is not possible, at least not in this way. You could even define two anonymous functions, like this:
var salvar;
if (a > 1) {
salvar = function() { /*faz alguma coisa que seria o você quer no Save() */ };
} else {
salvar = function() { /*faz outra coisa ou eventualmente não faz nada, seria o NoSave() */ };
}
I put in the Github for future reference.
There somewhere you would call salvar()
.
And I could do something like that too:
let salvar;
salvar = a > 1 ? function() { /*faz alguma coisa que seria o você quer no Save() */ } :
function() { /*faz outra coisa ou eventualmente não faz nada, seria o NoSave() */ };
There’s probably a better way to do what you need but without details you could only suggest this.
It worked :) . I’m Bur.. Really. Thank you very much. I will use in an if with confirmation of existence of a given file, if file exists it will ask confirmation if it runs Save(); if not confirmed it returns false, if the document does not exist it runs Save(); also this way it is perfectly working.
– Cleverson