Often, I define and call a function like this - particularly when we use flags:
function cat(doMeon, doCloseEyes)
{
if (doMeon) console.log("Meon...");
if (doCloseEyes) console.log("Hmm, I closed my eyes...");
}
...
// And then call, using flags. Names are temporary, only for readability
cat(doMeon=true, doCloseEyes=true);
Note that we could just do "cat(true, true)" but that kills the readability.
But the problem this introduces is that the two variables are now in global scope. And we shouldn't polluting the global scope. But we can't do this:
// Doesn't work...
cat(var doMeon=true, var doCloseEyes=true);
Is there an approach that one can use as best practice here? (Note: Defining these vars outside is not such a good idea.)
func(foo=true)style of invocation as a common practice? Are you trying to emulate another language?cat(var x)because it's a syntax error—the keyword var is a reserved word and can't be used where an identifier or expression is expected (var can only be used in a variable statement, which isn't an expression).