Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| webdev:javascript:basics [05/11/2018 17:32] – dolo | webdev:javascript:basics [02/12/2020 21:20] (Version actuelle) – [Basics] dolo | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== Basics ====== | ====== Basics ====== | ||
| - | + | * [[https:// | |
| - | Get the length of an object (ES5) : | + | * [[https:// |
| - | <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**, | * On Chrome **e.originalEvent.screenX** take different values than **e.originalEvent.clientX**, | ||
| + | == Pass additionnal parameters to an event using jQuery .trigger() == | ||
| + | <Code linenums> | ||
| + | // Trigger | ||
| + | $(' | ||
| + | { | ||
| + | console.log(e); | ||
| + | console.log(e.pageX); | ||
| + | $(' | ||
| + | }); | ||
| + | |||
| + | // We get the value as | ||
| + | $(' | ||
| + | { | ||
| + | console.log(e); | ||
| + | console.log(altPageX); | ||
| + | }); | ||
| + | </ | ||
| + | == Debouncing / Throttle == | ||
| + | * [[https:// | ||
| + | Throttle : Similar to debouncing but ensure a minimum execution of the function every fixed time | ||
| + | * [[https:// | ||
| + | |||
| + | Using jQuery' | ||
| ==== Promises ==== | ==== Promises ==== | ||
| * https:// | * https:// | ||
| Ligne 27: | Ligne 48: | ||
| </ | </ | ||
| + | ==== Objects ==== | ||
| + | === Object copy and references === | ||
| + | * [[https:// | ||
| + | <Code linenums> | ||
| + | var tmpDisable = {}; | ||
| + | var lastTmpDisable = {}; | ||
| + | |||
| + | lastTmpDisable = tmpDisable; // Any change made to any of these object will be on both because they' | ||
| + | |||
| + | // 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) === | ||
| + | <Code linenums> | ||
| + | var size = Object.keys(myObj).length; | ||
| + | </ | ||