zoukankan      html  css  js  c++  java
  • Javascript中的回调函数和匿名函数的回调示例介绍

    <!DOCTYPE html> 
    <html> 
    <head> 
    <meta charset="UTF-8"> 
    <title>Insert title here</title> 
    <script type="text/javascript"> 
    /* 
    * 匿名函数自调的意义: 
    1.营造了一个封闭的空间 
    2.防止变量冲突 
    3.有选择性的对外开发(第三方框架都是对js这样封装的) 
    */ 
    //==================普通函数回调================================= 
    //回调要执行的动作 
    function callback(){ 
    alert("帮我去快递吧"); 

    //正要做的事情 
    function goShopping(a,fun){ 
    alert("我去shopping了"); 
    //10点之前胡来要干的事情 
    if(a<10){ 
    fun(); 


    //回调测试 
    goShopping(9,callback); 
    //这个小例子就是一个回调函数运用的一个场景:当某些功能在执行的时候,并不知道未来可能干什么, 
    //同时,满足了一定的条件就会去做另一些动作,这个动作就是毁掉函数。 
    //==================普通函数回调================================= 
    //=================匿名函数的回调================================= 
    //正要做的事情 
    function goShopping(a,fun){ 
    alert("我去shopping了"); 
    //10点之前胡来要干的事情 
    if(a<10){ 
    fun(); 


    goShopping(9,function(){ 
    alert("帮我去快递的啦"); 
    }); 
    //=================匿名函数的回调================================= 
    //=================匿名函数的自己调用============================== 
    function(){ 
    alert("我没名,如何运行"); 
    }(); 
    //===============带参数的匿名函数的自己调用=============== 
    function(name){ 
    alert("我是"+name); 
    function test(){"我是大内密探!"}; 
    //要想外部调用内部的test 
    window.test=test; 
    }("javaScript"); 
    //调用自调函数的内部函数 
    test(); 
    //那么jquery等js的框架都是按照上述方式来写的哦。 
    //=================匿名函数的自己调用============================== 
    </script> 
    </head> 
    <body> 

    </body> 
    </html> 

  • 相关阅读:
    docker articles&videos
    Docker Resources
    IL-rewriting profiler
    memory dump and CLR Inside Out
    tcp/ip basics
    What Every CLR Developer Must Know Before Writing Code
    CLR profiler
    Debug CLR and mscorlib
    JIT Compiler
    calling into the CLR from managed code via QCall and FCall methods
  • 原文地址:https://www.cnblogs.com/asdyzh/p/9801790.html
Copyright © 2011-2022 走看看