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>
    坚持下去就能成功
  • 相关阅读:
    光与爱的世界
    [家里训练20_02_28]ABC
    [爬虫]美术作业,爬虫和百度图片
    [机器学习]第六、七周记录
    数据类型和对象
    设备对象
    进程、内存线程
    创建符号链接
    SCM管理器
    Nt内核函数原型and中文
  • 原文地址:https://www.cnblogs.com/suoking/p/5374440.html
Copyright © 2011-2022 走看看