Reputation: 954
I basically want to below code to work, is there a way ?
var hash_table = new Object();
hash_table['a'] = foo;
alert(hash_table['a'](1)); // 1 is just a simple parameter for example.
// this line should print "2" in alert();.
function foo(params) {
alert("params: " + params); // just simple print in alert(); (will print 1)
return 2;
}
Upvotes: 0
Views: 237
Reputation: 57690
You are defining foo
after using it. Make sure you define foo
first then use it.
So,
function foo(params) {
...
}
Should come before
hash_table['a'] = foo;
Upvotes: 1
Reputation: 74685
There is nothing wrong with that code. The code does what you describe it should do.
Upvotes: 0