每天CookBook之JavaScript-039

  • IIFE的使用
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>039</title>
</head>
<body>
    
</body>
<script type="text/javascript">
(function () {
    var i = 0;
    function increment(){
        i ++ ;
        console.log("value is " + i);
    }

    function runIncrement () {
        while (i < 5) {
            increment();
        }
    }

    window.onload = function(){
        runIncrement();
    }

})(); 
</script>
</html> 
posted @ 2016-07-17 21:41  4Thing  阅读(84)  评论(0编辑  收藏  举报