Attention: the list was moved to
https://github.com/dypsilon/frontend-dev-bookmarks
This page is not maintained anymore, please update your bookmarks.
Attention: the list was moved to
https://github.com/dypsilon/frontend-dev-bookmarks
This page is not maintained anymore, please update your bookmarks.
| // for detailed comments and demo, see my SO answer here http://stackoverflow.com/questions/8853396/logical-operator-in-a-handlebars-js-if-conditional/21915381#21915381 | |
| /* a helper to execute an IF statement with any expression | |
| USAGE: | |
| -- Yes you NEED to properly escape the string literals, or just alternate single and double quotes | |
| -- to access any global function or property you should use window.functionName() instead of just functionName() | |
| -- this example assumes you passed this context to your handlebars template( {name: 'Sam', age: '20' } ), notice age is a string, just for so I can demo parseInt later | |
| <p> | |
| {{#xif " name == 'Sam' && age === '12' " }} | |
| BOOM |
All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.
Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.
elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent| /** | |
| * Event loop. | |
| * | |
| * Read details here: | |
| * http://dmitrysoshnikov.com/ecmascript/javascript-the-core-2nd-edition/#job | |
| * | |
| * by Dmitry Soshnikov <[email protected]> | |
| */ | |
| /** |
Based on https://stackoverflow.com/a/31632215/761771
const reduceOp = function(args, reducer){
args = Array.from(args);
args.pop(); // => options
var first = args.shift();
return args.reduce(reducer, first);
};
I've recently ran into a pitfall of [React.memo()][memo] that seems generally overlooked; skimming over the top results in Google just finds it mentioned in passing in a [React issue][regit], but not in the [FAQ] or API [overview][react-api], and not in the articles that set out to explain React.memo() (at least the ones I looked at). The issue is specifically that nesting children defeats memoization, unless the children are just plain text. To give a simplified code example:
const Memoized = React.memo(({ children }) => (<div>{children}</div>));
// Won't ever re-render
<Memoized>bar</Memoized>
// Will re-render every time; the memoization does nothing| class Spiderman { | |
| lookOut() { | |
| alert('My Spider-Sense is tingling.'); | |
| } | |
| } | |
| let miles = new Spiderman(); | |
| miles.lookOut(); |