Reputation: 85
I want it works,but it only works on Chrome, in firefox and IE, it alert nothing,this's my code:
var name;
function say() {
alert(name);
}
function execute(someFunction, value) {
name = value;
someFunction;
}
execute(say(), "Hello");
Upvotes: 0
Views: 70
Reputation: 318568
The code is clearly wrong:
execute(say(), "Hello");
This passes the return value of say()
to execute
. However, you want to pass the function, so use execute(say, "Hello");
and in that function use someFunction()
to execute it.
Even though it probably/hopefully doesn't matter anymore, the code does work in Firefox - it alerts undefined
since say()
is executed before execute()
runs. The same thing happens in Chrome - however, it uses an empty alert box instead of showing the string undefined
since apparently chrome (or at least its developer console) has a global variable ?name? defined by default which is an empty string.
Upvotes: 3