Whatever
 22.07.2016 10:07

Статьи Array of functions in JavaScript

How to create array of functions in JavaScript?

Declare array and insert functions as cells:

var funcArray = [
	function () {
		alert('Function #1');
	},
	function () {
		alert('Function #2');
	},
	function () {
		alert('Function #3');
	}
];

How to serially execute functions from array?

var counter = 0;
for (var i = funcArray.length; i > 0; i--) {
	setTimeout(function () {
		funcArray.shift().call();
	}, ++counter * 500);
}

Leave a Reply

*