How to Implement Function Array in javascript

Source: Internet
Author: User

One of the biggest differences between JavaScript and java is that functions are considered as data and can be operated like an object in java. In addition, because js does not perform type check, Arrays can store anything. So I thought about whether to store functions in the array.

Implement the following functions:

After a function is called, it stores itself in an array (parameters are not allowed to be stored)

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

Originally, I wanted to use this method to execute the Undo function once (that is, each function stores itself in it. If Undo is used, the last function is removed and the entire queue is executed again ), later I thought it was too troublesome. However, the function array is implemented by pasting JSP
Copy codeThe Code is 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>

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.