How is it legal to use a function name as the argument to another function in JavaScript? -
I was ready for javascript but was reading the tutorial and came to this code:
function sorting (A, B) {return a - b; } Var n = ["10", "5", "40", "25", "100", "1"]; Document.write (n.sort (sortNumber));
These elements are very easy in the array. But how can we pass sortNumber
(name of a function) as a parameter for the sort function?
As they were variables.
Javascript manages the tasks in the same manner as the plan was planned. (Some people say "the functions are first class citizens.")
For example, you can type:
Foo = function () {Alert ('bar');}; // function like call foo foo ();
connector = function (x) {return function (y) {x + y}}; add5 = adder (5); add5 (1); // == 6
Hope this helps.
Comments
Post a Comment