GithubHelp home page GithubHelp logo

Comments (3)

kaiking01 avatar kaiking01 commented on May 30, 2024

他们主要区别在哪里?

from step-by-step.

KRISACHAN avatar KRISACHAN commented on May 30, 2024

别新开issue吖

from step-by-step.

YvetteLau avatar YvetteLau commented on May 30, 2024

函数节流 和 函数防抖 :
两者核心:使用setTimeout 和 clearTimeout 限制一个方法被频繁的触发。已达到减少请求的次数,减少服务器的压力。

参考上面的 https://www.jianshu.com/p/091c5fb96112 写了一遍
/函数节流(throttle)/
function throttle(fn,interval = 300){
let canRun = true;
return function(){
if(!canRun) return;
canRun = false;
setTimeout(()=>{
fn.apply(this,arguments);
canRun = true;
},interval)
}
}
/函数防抖(debounce)/
function debounce(fn,interval = 300){
let timeout =null;
return function() {
clearTimeout(timeout) // 清除时间
timeout = setInterval(()=>{
fn.apply(this,arguments);
},interval);
}
}

不要新开issue~

from step-by-step.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.