Methods to implement arrays of functions in javascript

  • 2020-03-30 01:04:13
  • OfStack

One of the biggest differences between js and languages like Java is that functions are also treated as data and can operate like an object in Java. And since js doesn't do type checking, arrays can hold anything. So I was wondering if I could store functions in an array.

Achieve the following functions:

The function stores itself in an array after it is called (it may not be stored as an argument)

Then you can use a large function to manipulate the array and call the function inside.

I was going to use this method to do an Undo function once (where each function stores itself in, and if an Undo removes the last function and executes the entire queue), but found it too cumbersome. But an array of functions does the trick: paste a JSP
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<input type="button" onclick="ff()" /> 
<script type="text/javascript"> 
list = new Array; 
f1 = function f1(flage) { 
if (flage) 
f2 = function f1(flage) { 
if (flage) 
function ff() { 
f = list.pop(); 
f = list.pop(); 

Related articles: