当前位置:网站首页>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 !
边栏推荐
- A brief talk on professional modeler: the prospect and professional development of 3D game modeling industry in China
- Bacteriostatic circle scanning correction template
- 1189. Maximum number of "balloons"
- Global and Chinese market of small batteries 2022-2028: Research Report on technology, participants, trends, market size and share
- Network communication basic kit -- IPv4 socket structure
- Override and virtual of classes in C #
- Portapack application development tutorial (XVII) nRF24L01 launch C
- Global and Chinese market for travel wheelchairs 2022-2028: Research Report on technology, participants, trends, market size and share
- Résumé: entropie, énergie libre, symétrie et dynamique dans le cerveau
- Example 072 calculation of salary it is known that the base salary of an employee of a company is 500 yuan. The amount of software sold by the employee and the Commission method are as follows: Sales
猜你喜欢
The contact data on Jerry's management device supports reading and updating operations [articles]
VRRP+BFD
Conditional statements of shell programming
LV1 tire pressure monitoring
Save Private Ryan - map building + voltage dp+deque+ shortest circuit
Database concept and installation
Push technology practice | master these two tuning skills to speed up tidb performance a thousand times!
Gee import SHP data - crop image
Setting function of Jerry's watch management device [chapter]
Small program graduation project based on wechat examination small program graduation project opening report function reference
随机推荐
Ai aide à la recherche de plagiat dans le design artistique! L'équipe du professeur Liu Fang a été embauchée par ACM mm, une conférence multimédia de haut niveau.
Hamburg University of Technology (tuhh) | intelligent problem solving as integrated hierarchical reinforcement learning
ZABBIX API pulls the values of all hosts of a monitoring item and saves them in Excel
Small program graduation project based on wechat e-book small program graduation project opening report function reference
Jerry's synchronous weather information to equipment [chapter]
Applet graduation project is based on wechat classroom laboratory reservation applet graduation project opening report function reference
Résumé: entropie, énergie libre, symétrie et dynamique dans le cerveau
Node write API
Jerry's update contact [article]
Buuctf QR code
String: LV1 eat hot pot
The difference between int (1) and int (10)
Chain ide -- the infrastructure of the metauniverse
The automatic control system of pump station has powerful functions and diverse application scenarios
Network byte order
Remember another interview trip to Ali, which ends on three sides
在尋求人類智能AI的過程中,Meta將賭注押向了自監督學習
Learn these super practical Google browser skills, girls casually flirt
A brief talk on professional modeler: the prospect and professional development of 3D game modeling industry in China
Hunan University | robust Multi-Agent Reinforcement Learning in noisy environment