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