Array of Function Pointers in JavaScript?

arrays, c++, function-pointers, javascript, pointers

Solution

You can just place references to your functions in an array. For example:

function func1() { alert("foo"); }
function func2() { alert("bar"); }
function func3() { alert("baz"); }
var funcs = [ func1, func2, func3 ];

funcs[0](); // "foo"

Of course, you can just as easily use anonymous functions like this:

var funcs = [ 
    function() { alert("foo"); }, 
    function() { alert("bar"); }, 
    function() { alert("baz"); } ];

funcs[0](); // "foo"

Problem

How can one implement an array of function pointers in JavaScript within their XHTML document? Today we learned in lecture how to implement JavaScript functions in an XHTML document, but what about arrays of function pointers? Can I pop a bunch of functions in an array and dereference them by index as one does in C++? Just curious...

Original source