js节流阀

js节流阀

'use strict';
(function(angular) {
    angular.module('throttleModule', [])
        .service('throttleService', ['$timeout', function($timeout) {
            /**
             * 描述
             * @author liuyiyang
             * @date 2021-09-26
             * @param {function} fn
             * @param {number} wait
             * @returns {function}
             */
            this.start = function(fn, wait) {
                var timer = null;
                return function(value) {
                    $timeout.cancel(timer);
                    timer = $timeout(function() {
                        fn(value);
                    }, wait);
                }
            };
        }]);
})(angular);

 

posted @ 2021-09-26 19:02  小猪章鱼  阅读(106)  评论(0编辑  收藏  举报