In JavaScript, all binding declarations are instantiated when control flow enters the scope in which they appear. Legacy var and function declarations allow access to those bindings before the actual declaration, with a "value" of undefined. That legacy behavior is known as "hoisting". let and const binding declarations are also instantiated when control flow enters the scope in which they appear, with access prevented until the actual declaration is reached; this is called the Temporal Dead Zone. The TDZ exists to prevent the sort of bugs that legacy hoisting can create.
| (function() { | |
| /** | |
| * 记录方法使用情况的类 | |
| * @param {Array.<boolean>} umMap 初始的使用情况 | |
| */ | |
| var UsageManager = function(umMap) { | |
| this.umMap = umMap || []; | |
| }; | |
| /** | |
| * 记录新的使用情况 |
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
| /* bling.js */ | |
| window.$ = document.querySelector.bind(document); | |
| window.$$ = document.querySelectorAll.bind(document); | |
| Node.prototype.on = window.on = function(name, fn) { this.addEventListener(name, fn); }; | |
| NodeList.prototype.__proto__ = Array.prototype; | |
| NodeList.prototype.on = function(name, fn) { this.forEach((elem) => elem.on(name, fn)); }; |
| /* | |
| * How to detect which element is the scrolling element in charge of scrolling the viewport: | |
| * | |
| * - in Quirks mode the scrolling element is the "body" | |
| * - in Standard mode the scrolling element is the "documentElement" | |
| * | |
| * webkit based browsers always use the "body" element, disrespectful of the specifications: | |
| * | |
| * http://dev.w3.org/csswg/cssom-view/#dom-element-scrolltop | |
| * |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| /* | |
| This is for demonstration purposes. Ideally, you should never use the star selector. | |
| I recommend that you use this early on in your development, and then once you've established | |
| your HTML element palette, go back and replace * with a comma-separated list of your | |
| tag names. Additionally, the !important shouldn't have to be used, but I'm leaving it here | |
| because some enterprising goons will probably copy and paste this directly into their project - | |
| the !important will ensure these settings override other attempts that were either never | |
| deleted or are part of an installed CSS file the user is unaware of. | |
| */ | |
| * { |
Angular doesn’t depend on jQuery. In fact, the Angular source contains an embedded lightweight alternative: jqLite. Still, when Angular detects the presence of a jQuery version in your page, it uses that full jQuery implementation in lieu of jqLite. One direct way in which this manifests itself is with Angular’s element abstraction. For example, in a directive you get access to the element that the directive applies to:
| // ABC - a generic, native JS (A)scii(B)inary(C)onverter. | |
| // (c) 2013 Stephan Schmitz <[email protected]> | |
| // License: MIT, http://eyecatchup.mit-license.org | |
| // URL: https://gist.github.com/eyecatchup/6742657 | |
| var ABC = { | |
| toAscii: function(bin) { | |
| return bin.replace(/\s*[01]{8}\s*/g, function(bin) { | |
| return String.fromCharCode(parseInt(bin, 2)) | |
| }) | |
| }, |
| git filter-branch --tree-filter 'git ls-files -z | xargs -0 dos2unix' -- --all |