JavaScript anonymous functions and callback functions

Source: Internet
Author: User

Format:
(function() {// Code }) ();

function expressions can be stored in variables, and variables can be used as a function to pass anonymous functions as parameters to other functions, the receiver function can be passed in by the function to complete some functions can be performed through anonymous functions of some one-time tasks
<!doctype html>// Test code URI function    var test1=  function(x, y) {return x*y;    }; var test2=function(x, y) {return x+y;};    Alert (test1 (3,5));    Alert (test2 (2,6)); </script></body>

callback function saves global variables and improves performance
<script type= "Text/javascript" >//function to test the encoding URI    //var test1=function (x, y) {return x*y;};    //var test2=function (x, y) {return x+y;};    //Alert (test1 (3,5));    //alert (test2 (2,6));    //example of a callback function    functionCalc (x, y) {returnX () +y (); }    functiontest3 () {return3; }    functiontest4 () {return5; }    //Alert (Calc (test1,test2));Alert (Calc (function(){return10;},function(){return5;}));</script>

function returns 15

JavaScript anonymous functions and callback functions

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.