Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| lwc:programming:javascript [2020/11/26 22:29] – created John Harrison | lwc:programming:javascript [2025/03/18 13:58] (current) – John Harrison | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| - | | find all elements ids with class " | + | | find all elements ids with class " |
| | callback function when mouse leaves button_8 | | callback function when mouse leaves button_8 | ||
| | set style of myPath2 | | set style of myPath2 | ||
| | get caller of function | | get caller of function | ||
| | find all methods of an object | | find all methods of an object | ||
| - | | loop through a set of values | + | | loop through a set of values |
| Line 37: | Line 37: | ||
| wrapping a function: | wrapping a function: | ||
| - | <HTML>< | + | <code> |
| If you have a function call and you need to send it parameters (such as | If you have a function call and you need to send it parameters (such as | ||
| $(document).on(" | $(document).on(" | ||
| $(document).on(" | $(document).on(" | ||
| - | myFunction(parameter)});</ | + | myFunction(parameter)}); |
| - | \\ | + | </code> |
| Garbage Collection: | Garbage Collection: | ||
| Line 50: | Line 49: | ||
| * you can call Garbage Collection yourself in Chrome by [[https:// | * you can call Garbage Collection yourself in Chrome by [[https:// | ||
| + | ==== Console Fun ==== | ||
| + | * to see all the event messages flying around: '' | ||
| + | * then to unsee: '' | ||
| + | ==== Promises ==== | ||
| + | Promises are always async and often used to prevent UI blocking when waiting for something like an I/O interface. If a function has a '' | ||
| + | === Creating the promise (producing) === | ||
| + | < | ||
| + | myPromise = Promise(success, | ||
| + | // do something that takes some time here | ||
| + | if (succeeded) { | ||
| + | success() { // what to return on success i.e. " | ||
| + | else | ||
| + | failure() { // what to return on failure }; // this is not a function but only a return value | ||
| + | } | ||
| + | </ | ||
| + | === Calling or running the promise (consuming) === | ||
| + | == Using .then(onFulfilled, | ||
| + | //this is the less preferred method// | ||
| + | < | ||
| + | myPromise.then( | ||
| + | successFunction(value) { // do stuff here with value which was returned by ' | ||
| + | failFunction(value) { // do stuff here with value returned by ' | ||
| + | </ | ||
| + | == Using .catch == | ||
| + | // this is best practice in general // | ||
| + | < | ||
| + | myPromise.then( | ||
| + | successFunction(value) { // do stuff here with value returned by ' | ||
| + | .catch(failFunction(value) { // do stuff here with value returned by ' | ||
| + | </ | ||
| + | ==== Arrow Notation ==== | ||
| + | ^ Category ^ Old Skool ^ Arrow Function | ||
| + | | No Parameter | ||
| + | | One Parameter | ||
| + | | Two Parameters | ||