Methods to implement array of functions in JavaScript _javascript tips

Source: Internet
Author: User
One of the biggest differences between JS and Java is that functions are also considered data and can operate like an object in Java. And because JS does not perform type checking, the array can store anything. So I wondered if the array could hold a function.

The following features are implemented:

function to store itself in an array after invocation (can not be stored according to the parameters)

You can then use a large function to manipulate the array and call the functions in it.

I would have used this method to perform a undo function (that is, each function stores itself in, and if undo eliminates the last function and executes the entire queue), then it feels too cumbersome. But the function array function is implemented: Paste JSP
Copy Code code as follows:

<%@ page language= "java" contenttype= "text/html; charset=iso-8859-1" br>pageencoding= "Iso-8859-1"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
<meta http-equiv= "Content-type" content= "text/html; charset=iso-8859-1" >
<title >MothedList</title>
<body>
<input type= "button" onclick= "ff ()"/> Br><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>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.