当前位置:网站首页>I stepped on a foundation pit today
I stepped on a foundation pit today
2022-07-04 02:25:00 【Programming samadhi】

introduction
I wonder if you have such an experience : It's wrong to suddenly find out that you have a deep-rooted view for a long time ?
I stepped on a pit today : I always remember in my impression setInterval After definition, it will Execute now Once inside the logic , So when implementing the logic in the figure below , I will take the second step (” Execute the logic immediately a“) It's not necessary , This province has brought me a bug, Khan, ~

It's out bug, We need to remedy , Don't lose your attitude !
Bronze grade
Speaking of the simplest fix , That's the method we often use , The code is as follows :
Yes , It's so simple and plain !
Diamond grade
Since it's diamond grade , Then you have to play some tricks , Otherwise, it will be useless .
In fact, there is a hidden danger in the above bronze level implementation : It cannot be ensured that there is only one timer executing this logic at the same time . Then let's encapsulate :
Xingyao class
Use the objective function to return the objective function itself .
Um. , The code style is a little higher .
King level
Since it needs to be executed immediately , Then why not use self executing functions ?
Although the logic is the same as above , But I don't know why it's a little tall ,-
Conclusion
In fact, I still don't understand why I have such a wrong memory , And no correction has been found for so long .
It's not terrible to make mistakes , The terrible thing is that you don't realize you've made a mistake !
It takes a good blacksmith to make steel. , Don't look at how big others' implementation methods are , In fact, it is the result of some reasonable combination of basic knowledge , As long as you have a good foundation , Even in the face of a simple piece of code, you can play a different trick !
- ~
- The end of this paper , Thank you for reading !
~
Learn interesting knowledge , Make interesting friends , Create interesting souls !
Hello everyone , I am a 〖 The samadhi of programming 〗 The author of Hermit King , My official account is 『 The samadhi of programming 』, Welcome to your attention , I hope you can give me more advice !
边栏推荐
- Gee import SHP data - crop image
- Global and Chinese market of cell scrapers 2022-2028: Research Report on technology, participants, trends, market size and share
- A. Div. 7
- Comment la transformation numérique du crédit d'information de la Chine passe - t - elle du ciel au bout des doigts?
- Global and Chinese market of handheld melanoma scanners 2022-2028: Research Report on technology, participants, trends, market size and share
- MySQL workbench use
- String & memory function (detailed explanation)
- Valentine's Day - 9 jigsaw puzzles with deep love in wechat circle of friends
- Yyds dry goods inventory it's not easy to say I love you | use the minimum web API to upload files
- 15. System limitations and options
猜你喜欢

3D game modeling is in full swing. Are you still confused about the future?

17. File i/o buffer

Small program graduation design is based on wechat order takeout small program graduation design opening report function reference

Node write API

1189. Maximum number of "balloons"

長文綜述:大腦中的熵、自由能、對稱性和動力學

The "message withdrawal" of a push message push, one click traceless message withdrawal makes the operation no longer difficult

Final consistency of MESI cache in CPU -- why does CPU need cache

Conditional statements of shell programming

Iclr2022 | ontoprotein: protein pre training integrated with gene ontology knowledge
随机推荐
Global and Chinese market of thin film deposition systems 2022-2028: Research Report on technology, participants, trends, market size and share
C learning notes: C foundation - Language & characteristics interpretation
Description of setting items of Jerry [chapter]
A. Div. 7
Neo4j learning notes
STM32 key content
Sword finger offer 20 String representing numeric value
A. Min Max Swap
Keep an IT training diary 054- opening and closing
Data collection and summary
PTA tiantisai l1-079 tiantisai's kindness (20 points) detailed explanation
Life cycle of instance variables, static variables and local variables
Introduction to graphics: graphic painting (I)
Unspeakable Prometheus monitoring practice
AI 助力藝術設計抄襲檢索新突破!劉芳教授團隊論文被多媒體頂級會議ACM MM錄用
Hunan University | robust Multi-Agent Reinforcement Learning in noisy environment
Solve the problem that the tabbar navigation at the bottom of vantui does not correspond to the page (window.loading.hash)
Jerry's watch listens to the message notification of the target third-party software and pushes the message to the device [article]
Day05 branch and loop (II)
A brief talk on professional modeler: the prospect and professional development of 3D game modeling industry in China