Function throttling plays a large role in daily DOM interface data interactions, reducing server requests while reducing client memory impact
Underscore.js This province contains the functions of function throttling
_.throttle and _.debounce
The simple tests are used as follows:
The class library you need to use is jquery, underscore
The method of testing is: MouseMove event
The test page code is as follows:
<!DOCTYPE HTML><HTML><Head> <Scriptsrc= "Jquery-1.11.1.min.js"type= "Text/javascript"></Script> <Scriptsrc= "Underscore-min.js"type= "Text/javascript"></Script> <Scripttype= "Text/javascript">$ (document). Ready (function () { $('#infoapp'). On ('MouseMove', Alertinfo); Do not use throttling methods//$ (' #infoapp '). On (' MouseMove ', _.throttle (Alertinfo, 5000)); Using throttling method Throttle //$ (' #infoapp '). On (' MouseMove ', _.debounce (Alertinfo, +, false)); Using throttling method Debounce } ) //event handler function for callback functionAlertinfo () {varData= NewDate (); Console.log (data); } </Script></Head><Body> <DivID= "Infoapp"style= "background-color:red; width:200px; height:200px; margin:0 auto; "> </Div></Body></HTML>
The results of the test are as follows:
Conclusion:
In general, we have a great deal of help in the way we use function throttling in the Ajax interactions of dense data requests, reducing a lot of unnecessary data requests.
Underscore.js function Throttling Simple test