JS Call function immediately

Source: Internet
Author: User

        functionMakecounter () {//cannot be executed immediately            //I can only be accessed within the Makecounter            vari = 0; return function() {Console.log (++i);        }; }        varCounter = Makecounter ();//Object 1Counter ();//logs:1//Immediate executionCounter ();//Logs:2        varCounter2 = Makecounter ();//Object 2Counter2 ();//logs:1Counter2 ();//Logs:2        varFoo =function() {Console.log ("/* code * *")};//no direct Operation .        varFoo =function() {Console.log ("/* code * *")} ();//Run directly        functionFF () {/*Code*/}();//syntaxerror:unexpected Token error        functionFF () {Console.log ("/* code * *")} (1);//No exception, no output        functionFoo () {Console.log ("/* Code * *")}; (1);//No error, no output        (function() {Console.log ("/* code * *")} ());//It is recommended to use this direct output(function() {Console.log ("/* code * *")});//But this is also a direct output that can be used        vari =function() {Console.log ("/* code * *")} ();//Direct Output        true&&function() {Console.log ("/* code * *")} ();//Direct Output0,function() {Console.log ("/* code * *")} ();//Direct Output!function() {Console.log ("/* code * *")} ();//Direct Output~function() {Console.log ("/* code * *")} ();//Direct Output-function() {Console.log ("/* code * *")} ();//Direct Output+function() {Console.log ("/* code * *")} ();//Direct Output        New function() {Console.log ("/* code * *")};//Direct Output        New function() {Console.log ("/* code * *")} ();//Direct Output                functionff () {New function() {Console.log ("/* Code * *") }; !function() {Console.log ("/* Code * *") }();  } ff (); Direct Output

  ! function () {Console.log ("/* Code */1")} (Console.log ("/* Code */2")); // Direct Output  executes 2 in execution 1

JS Call function immediately

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.