====== Basics ====== * [[https://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery#answer-12034334|Escape HTML]] * [[https://www.sitepoint.com/delay-sleep-pause-wait/|Delay sleep pause wait]] - or lack thereof [[https://www.w3schools.com/js/js_timing.asp|Doc]] * ... ==== Events ==== * [[https://www.w3schools.com/tags/ref_eventattributes.asp|Basic HTML events]] * [[https://developer.mozilla.org/en-US/docs/Web/Events|Basic javascript events]] * [[https://medium.com/@jacobwarduk/how-to-correctly-use-preventdefault-stoppropagation-or-return-false-on-events-6c4e3f31aedb|How to correctly use preventDefault(), stopPropagation(), or return false; on events]] * On Chrome **e.originalEvent.screenX** take different values than **e.originalEvent.clientX**, unlike Firefox. == Pass additionnal parameters to an event using jQuery .trigger() == // Trigger $('.volume').on('mousemove', function(e) { console.log(e); console.log(e.pageX); $('.volume').trigger('mousedown', [e.pageX] ); }); // We get the value as $('.volume').on('mousedown', function(e, altPageX) { console.log(e); console.log(altPageX); }); == Debouncing / Throttle == * [[https://eloquentjavascript.net/15_event.html#h_AOVmaqj10I|Source]] Throttle : Similar to debouncing but ensure a minimum execution of the function every fixed time * [[https://css-tricks.com/debouncing-throttling-explained-examples/#article-header-id-5|Source]] Using jQuery's .one() can also work. ==== Promises ==== * https://javascript.info/promise-basics * https://javascript.info/promise-chaining ==== Check if a variable exist in javascript without getting an error ==== [[https://stackoverflow.com/questions/858181/how-to-check-a-not-defined-variable-in-javascript#answer-858193|Source]] if( typeof google_step != 'undefined') { // ... } ==== Objects ==== === Object copy and references === * [[https://stackoverflow.com/questions/16880418/javascript-pass-object-as-reference|Basic copy with = is just a reference, not new object]] var tmpDisable = {}; var lastTmpDisable = {}; lastTmpDisable = tmpDisable; // Any change made to any of these object will be on both because they're references // If we declare it this way a new object is created for(var key in tmpDisable) { lastTmpDisable[key] = tmpDisable[key] } === Get the length of an object (ES5) === var size = Object.keys(myObj).length;