Array of Function Pointers in JavaScript?

user3250884

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...

p.s.w.g

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"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Passing "array of pointers" to function

From Dev

C array of function pointers

From Dev

Free array of function pointers

From Dev

Passing An Array of Pointers to Function

From Dev

Accessing array of function pointers

From Dev

C -- Array of Function Pointers

From Dev

Malloc an array of function pointers

From Dev

Passing array of pointers into a function

From Dev

C -- Array of Function Pointers

From Dev

Filling an array of pointers in a function

From Dev

Free array of function pointers

From Dev

Passing An Array of Pointers to Function

From Dev

Passing array of pointers into a function

From Dev

Array of Array of function pointers in C

From Dev

Coding printf with array of function pointers

From Dev

Modifiying array pointers inside a function

From Dev

javascript pointers array or #define for abbreviation

From Dev

javascript pointers array or #define for abbreviation

From Dev

How to pass array of function pointers to another function

From Dev

How to call a function that is in an array of function pointers?

From Dev

Pass array of function pointers via SWIG

From Dev

Storing SYSCALL functions in array of function pointers

From Dev

Unable to "point to" passed array of function pointers in C

From Dev

C - How to setup an associative array of function pointers?

From Dev

C - how to modify an array of pointers inside of a function

From Dev

How do I return an array of pointers in a function?

From Dev

C++ Declaring An Array Of Function Pointers

From Dev

How to return an array from a function with pointers

From Dev

Passing an array of character pointers to a C function