首页 > 技术文章 > js节流阀

yiyangl 2021-09-26 19:02 原文

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);

 

推荐阅读