Skip to content

Instantly share code, notes, and snippets.

@ghostcode
Last active December 21, 2022 01:27
Show Gist options
  • Select an option

  • Save ghostcode/65b0f7455d48e2375650cc114e13e7c4 to your computer and use it in GitHub Desktop.

Select an option

Save ghostcode/65b0f7455d48e2375650cc114e13e7c4 to your computer and use it in GitHub Desktop.

Revisions

  1. ghostcode revised this gist Dec 21, 2022. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion throttle.md
    Original file line number Diff line number Diff line change
    @@ -18,4 +18,5 @@
    },wait)
    }
    }
    }
    }
    ```
  2. ghostcode revised this gist Dec 21, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion throttle.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    ··
    ```
    function throttle(fn,wait=3000){
    let lastTime = Date.now(),
    timeFlag = null
  3. ghostcode revised this gist Dec 21, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion throttle.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@

    ··
    function throttle(fn,wait=3000){
    let lastTime = Date.now(),
    timeFlag = null
  4. ghostcode revised this gist Dec 21, 2022. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion throttle.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    function throttle(fn,wait=3000){

    function throttle(fn,wait=3000){
    let lastTime = Date.now(),
    timeFlag = null

  5. ghostcode renamed this gist Dec 21, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. ghostcode revised this gist Dec 21, 2022. No changes.
  7. ghostcode revised this gist Dec 21, 2022. No changes.
  8. ghostcode revised this gist Dec 21, 2022. 1 changed file with 20 additions and 1 deletion.
    21 changes: 20 additions & 1 deletion throttle
    Original file line number Diff line number Diff line change
    @@ -1 +1,20 @@
    ‎‎​
    function throttle(fn,wait=3000){
    let lastTime = Date.now(),
    timeFlag = null

    return function(...args){
    let current = Date.now()

    clearTimeout(timeFlag)

    if(current - lastTime >= wait){
    fn.apply(this,args)
    lastTime = current
    }else{
    timeFlag = setTimeout(()=>{
    fn.apply(this,args)
    lastTime = current
    },wait)
    }
    }
    }
  9. ghostcode created this gist Dec 21, 2022.
    1 change: 1 addition & 0 deletions throttle
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    ‎‎​