Return to Snippet

Revision: 4367
at December 2, 2007 07:59 by 1man

Initial Code
function functionsDontNeedNames(){
	var a = new Array(3);//create array length 3
	a[0] = function(x){return x*x};//this is now the function
	a[1] = 4;//will be used as 'x'
	a[2] = a[0](a[1]);//a[2] now equals 16!

Initial URL

Initial Description
The important thing to notice is the () operator in a[2]. It is invoking the function inside a[0] with the argument a[1].

Initial Title
Array Functions as Data

Initial Tags
data, array, function

Initial Language