Is it possible to set a variable to be equal to a function without using a shell?
In JavaScript, you can set a variable equal to a method like this:
variable = function () { alert("My name is bob"); };
Or like this:
function SayMyName() {
alert("My name is bob");
}
variable = SayMyName;
You can also wrap a function with arguments like this:
function SayMyName(name) {
alert("My name is "+ name);
}
variable = function () { SayMyName("bob"); };
But when trying to store the variable, the following call will call the function rather than store it as a variable:
function SayMyName(name) {
alert("My name is "+ name);
}
variable = SayMyName("bob");
There was a clever way you could work using [callee] [1], but the callable is deprecated and won't work in most modern browsers.
Is there a way to set a variable equal to a function with arguments without using a shell?
+3
source to share
5 answers