Outils pour utilisateurs

Outils du site


webdev:javascript:basics

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
webdev:javascript:basics [05/11/2018 18:41]
dolo [Objects]
webdev:javascript:basics [02/12/2020 21:20] (Version actuelle)
dolo [Basics]
Ligne 1: Ligne 1:
 ====== Basics ====== ====== Basics ======
- +  * [[https://stackoverflow.com/questions/24816/escaping-html-strings-with-jquery#answer-12034334|Escape HTML]] 
-Get the length of an object (ES5) :  +  * [[https://www.sitepoint.com/delay-sleep-pause-wait/|Delay sleep pause wait]] - or lack thereof [[https://www.w3schools.com/js/js_timing.asp|Doc]] 
-<Code linenums> +  * ...
-var size = Object.keys(myObj).length; +
-</Code>+
  
 ==== Events ==== ==== Events ====
Ligne 13: Ligne 11:
   * On Chrome **e.originalEvent.screenX** take different values than **e.originalEvent.clientX**, unlike Firefox.   * On Chrome **e.originalEvent.screenX** take different values than **e.originalEvent.clientX**, unlike Firefox.
  
 +== Pass additionnal parameters to an event using jQuery .trigger() ==
 +<Code linenums>
 +// 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);
 +});
 +</Code>
 +== 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 ==== ==== Promises ====
   * https://javascript.info/promise-basics   * https://javascript.info/promise-basics
Ligne 28: Ligne 49:
  
 ==== Objects ==== ==== 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]]   * [[https://stackoverflow.com/questions/16880418/javascript-pass-object-as-reference|Basic copy with = is just a reference, not new object]]
 <Code linenums> <Code linenums>
Ligne 40: Ligne 62:
  lastTmpDisable[key] = tmpDisable[key]  lastTmpDisable[key] = tmpDisable[key]
  }  }
 +</Code>
 +
 +=== Get the length of an object (ES5) ===
 +<Code linenums>
 +var size = Object.keys(myObj).length;
 </Code> </Code>
webdev/javascript/basics.1541439711.txt.gz · Dernière modification: 05/11/2018 18:41 de dolo