Another intersting concept that I came across:
Java Script allows you to create an array of functions, took me a while to make this work but I finally got it. Here is example of how to do this:
<!DOCTYPE html>
<html>
<head>
<title>Array of functions</title>
<script type="text/javascript">
function transform(array)
{
function makeFunction(value)
{return function()
{
return value;
}
}
var output = new Array();
for(var i = 0; i < array.length; ++i)
{
output[i] = makeFunction(array[i]);
}
return output;
}
</script>
</head>
<body>
<script type="text/javascript">
myArray = [1,2,3,4,5];
myArray = transform(myArray);
for(var i =0 ; i < myArray.length; ++i)
{
alert( myArray[i]());
}
</script>
</body>
</html>
I started this blog as a personal notepad, but it seems I'm getting more and more hits. Since people are reading this I starting sharing anything that I find interesting or usfull. I'm currently dedicating my time to expanding my knowledge into the more modern languages and ideas. If you find this information useful or a waste of your tome let me know by leaving commits or using the google +1 function at the bottom of the post. Thanks for viewing Daniel Haro
Showing posts with label Array of Functions. Show all posts
Showing posts with label Array of Functions. Show all posts
Thursday, August 16, 2012
Subscribe to:
Posts (Atom)