zoukankan      html  css  js  c++  java
  • javascript的模块开发方法;

    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
    <script>
        //模块开发模式;
    //    var someModule = (function(){
    //        //TODO
    //    }());
    //    第一种返回方式;
    //    var someModule = (function(){
    //        var count = 0;
    //        return {
    //            addCount:function(){
    //                return count++;
    //            },
    //            getCount: function(){
    //                return count;
    //            },
    //            resetCount: function(){
    //                console.log(count);
    //                count = 0;
    //            }
    //        }
    //    }());
    //    第二种返回方式;
        var someModule = (function(){
            var count = 0;
                var addCount = function(){
                    return count++;
                }
                var getCount = function(){
                    return count;
                }
                var resetCount = function(){
                    console.log(count);
                    count = 0;
                }
            return {
                addCount: addCount,
                getCount: getCount,
                resetCount: resetCount
    
            }
        }());
        someModule;
        var a1 = someModule;
        console.log(someModule.addCount());
        console.log(someModule.addCount());
        console.log(someModule.addCount());
        console.log(a1.addCount());
        a1.resetCount();
        console.log(a1.getCount());
    </script>
    </body>
    </html>
    坚持下去就能成功
  • 相关阅读:
    Makefile Special Built-in Target Names(Makefile内建特殊目标)
    著名的变量命名规则
    bottle py
    LuCI中文手册
    LuCI
    LuCI2 (OpenWrt web 管理界面)
    LuCI2 (OpenWrt web user interface)
    OpenWrt netifd
    加载时间/性能
    Taming the asynchronous beast with ES7
  • 原文地址:https://www.cnblogs.com/suoking/p/5374440.html
Copyright © 2011-2022 走看看