首页 > 编程语言 > 详细

javascript的模块开发方法;

时间:2016-04-10 17:35:26      阅读:236      评论:0      收藏:0      [点我收藏+]
<!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>

 

javascript的模块开发方法;

原文:http://www.cnblogs.com/suoking/p/5374440.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!