A brief analysis of JavaScript higher order function

Source: Internet
Author: User

What are high-order functions: In Mathematics and computer science, higher-order functions are functions that meet at least one of the following conditions: 1, accept one or more functions as input, 2, output a function. In mathematics they are also called operators (operators) or functional. The derivative in calculus is a common example, because it maps a function to another function. In functional programming, the higher-order function that returns another function is called the curry function.

Obviously JavaScript and Python are examples of higher-order function features. To see the characteristics of higher order functions, a topic is given below, and an add function is written to meet the following computational capabilities:

Add (1) (2) (3) (4)//return 10

From the point of view, it is obvious that add (1) will return a function in order to make a chain call. Of course, the difficulty is that the final need to return a number, and according to the previous request add () call must return a function. The core of this paper is not to discuss its implementation methods, interested readers can self-study, the following directly to implement the source code:

varadd = (function() {vartotal=0;functionCCC (v) {Total + = V;returnCCC;};ccc.valueof =function(){vartemp = total;Total =0;returntemp;}returnCCC;})();

As can be seen from the above example, the function of CCC by returning the function itself, to achieve the purpose of the chain call, which is one of the characteristics of the higher-order function, and another feature is to enter the function as a parameter.

A brief analysis of JavaScript higher order function

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.