PageSourceSearch

https://eloquent-khapse-98a9d2.netlify.app/js/utils/index.js

js eloquent-khapse-98a9d2.netlify.app collected 2026-10-03 10:41:52 UTC 1,433 bytes, 52 lines download raw bytes

1const bamboo = {
2  // 函数防抖
3  throttle: function (func, wait, options) {
4    let timeout, context, args
5    let previous = 0
6    if (!options) options = {}
7
8    const later = function () {
9      previous = options.leading === false ? 0 : new Date().getTime()
10      timeout = null
11      func.apply(context, args)
12      if (!timeout) context = args = null
13    }
14
15    const throttled = function () {
16      const now = new Date().getTime()
17      if (!previous && options.leading === false) previous = now
18      const remaining = wait - (now - previous)
19      context = this
20      args = arguments
21      if (remaining <= 0 || remaining > wait) {
22        if (timeout) {
23          clearTimeout(timeout)
24          timeout = null
25        }
26        previous = now
27        func.apply(context, args)
28        if (!timeout) context = args = null
29      } else if (!timeout && options.trailing !== false) {
30        timeout = setTimeout(later, remaining)
31      }
32    }
33
34    return throttled
35  },
36  // 函数节流
37  debounce: function (func, wait, immediate) {
38    let timeout
39    return function () {
40      const context = this
41      const args = arguments
42      const later = function () {
43        timeout = null
44        if (!immediate) func.apply(context, args)
45      }
46      const callNow = immediate && !timeout
47      clearTimeout(timeout)
48      timeout = setTimeout(later, wait)
49      if (callNow) func.apply(context, args)
50    }
51  },
52};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.