Giter VIP home page Giter VIP logo

Comments (8)

mqyqingfeng avatar mqyqingfeng commented on August 19, 2024 9

timeout = null设置为null,不仅仅是为了防止内存泄漏,而是clearTimeout(timeout)后,timeout的值并不会清空,如果不设置为null,就不能根据!timeout设置下次的timeout

from underscore-analysis.

johnsoncheg avatar johnsoncheg commented on August 19, 2024

问个问题,remaing > wait 这种情况好像不可能发生吧

from underscore-analysis.

lessfish avatar lessfish commented on August 19, 2024

@johnson-tech

有注释

// remaining > wait,表示客户端系统时间被调整过

from underscore-analysis.

johnsoncheg avatar johnsoncheg commented on August 19, 2024

@hanzichi 不好意思,眼拙了- -

from underscore-analysis.

ginnko avatar ginnko commented on August 19, 2024

大神,想问下这里:

  1. previous = options.leading === false ? 0 : _.now(); 这里previous始终赋值为_.now()感觉也是可以正常运行的,不太明白为何这里要做这个选择.
  2. if (!previous && options.leading === false)这里感觉去掉!previous也可以运行, 也不太明白为何要增加这样一个判断

from underscore-analysis.

yinguangyao avatar yinguangyao commented on August 19, 2024

@ginnko
1、如果是在leading为false的情况下,每次触发后一定会延迟wait时间才会调用later函数,如果将这个判断去掉,那么会出现一种情况就是,我执行later后很长时间(超过wait)没有触发(比如我触发scroll的时候突然我就不滚动页面了),那么now-previous就会大于wait,导致remaining为负数,会直接调用func函数,这样这次执行就不会延迟wait时间了。
2、这种情况下我就不清楚了,看起来只会在leading和trailing同时为false的时候去掉!previous才会出现问题,这个时候如果去掉!previous会导致func函数永远不会执行,但是看他们并不推荐两个同时为false

from underscore-analysis.

wangliang1124 avatar wangliang1124 commented on August 19, 2024

@ginnko 2去掉之后remaining就一直等于wait,if 语句还怎么执行

from underscore-analysis.

yinguangyao avatar yinguangyao commented on August 19, 2024

@anotherleon
if语句是肯定不会执行了,但是会走else if语句,下面还是可以正常运行的。

from underscore-analysis.

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.