One of the biggest differences between js and languages like java is that functions are also regarded as data and can be operated like an object in java. And since js does not perform type checking, arrays can store anything. So I wondered if functions could be stored in arrays.
Implement the following functions:
After the function is called, it stores itself in the array (it can not be stored according to the parameters)
You can then use a large function to manipulate the array and call the functions within it.
Originally, I wanted to use this method to execute the Undo function (that is, each function stores itself in it, and if it is Undo, the last function is eliminated and the entire queue is executed), but later I felt that this was too troublesome. However, the function of the function array is realized: paste JSP
Copy the code code as follows:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>MothedList</title>
</head>
<body>
<input type="button" onclick="ff()" />
<script type="text/javascript">
list = new Array;
f1 = function f1(flage) {
alert("f1");
if(flage)
list.push(f1);
}
f2 = function f1(flage) {
alert("f2");
if(flage)
list.push(f2);
}
function ff() {
f1(true);
f2(true);
f = list.pop();
f(false);
f = list.pop();
f();
}
</script>
</body>
</html>