함수 절전 데모

3411 단어 demo

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Documenttitle>
head>
<body>
    <script>
        var  jlFn= function(fn, wait){
            var  stime = 0,etime;
            var  isPause = true;

            function result() {
                etime = Date.now();
                if (etime - stime < wait && isPause === true) {
                    return;
                } else {
                    fn()
                }
                stime = etime;
            }
            result.flash = function () {// , 
                fn()
            }
            result.pause = function () {// 
                isPause = true;
            }
            result.resume = function () {// 
                isPause = false;
            }
            return result;
        }

        function print() {
            console.log('print something')
        }
        var tPrint = jlFn(print,2000);
        setInterval(function(){
             tPrint ();
        })

    script>
body>
html>

좋은 웹페이지 즐겨찾기