随笔分类 - Javascript
摘要:function logThis() { console.log(this) } const obj = { logThis, logThis2() { logThis() }, logThis3() { obj.logThis() } } obj.logThis(); obj.logThis2()
阅读全文
摘要:Web API, such as setTimeout setInterval which goes into Macrotask Queue; Microtask such as, code after await, Promise, all go to Microtask Queue direc
阅读全文
摘要:Refer to post: http://shebang.mintern.net/foolproof-html-escaping-in-javascript/ Code: var ESC_MAP = { '&': '&', '<': '<', '>': '>', '"': '&
阅读全文
摘要:const generateTimeMs = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min /** * A generator which can generate numbers based on settings
阅读全文
摘要:class Observable { constructor(subscribe) { this._subscribe = subscribe; } subscribe(observer) { return this._subscribe(observer); } static of(value)
阅读全文
摘要:class Observable { constructor(subscribe) { this._subscribe = subscribe; } subscribe(observer) { return this._subscribe(observer); } static concnat(..
阅读全文
摘要:function Observable(forEach) { this._forEach = forEach; } Observable.prototype = { forEach: function (onNext, onError, onCompleted) { if (typeof onNex
阅读全文
摘要:<Parent> <child> <button /> </child> </Parent> function onClick(event) { console.log('target: ', event.target) // button console.log('currentTarget',
阅读全文
摘要:Mistake 1: Not using the same function reference // Wrong button.addEventListener('click', () => {console.log('click')}) button.removeEventListener('c
阅读全文
摘要:When Virtual keyboard popup, we can relayout the UI element accordingly: navigator.virtualKeyboard.overlaysContent = true; navigator.virtualKeyboard.s
阅读全文
摘要:Run the following code, found that for get & push & pop, it is O(1) time; But for shift/unshfit, it is O(n) time. In this cases, Javascript's [], is a
阅读全文
摘要:const $ = () => document.querySelector.call(this, arguments); const $$ = () => document.querySelectorAll.call(this, arguments); HTMLElement.prototype.
阅读全文
摘要:Solution 1: consider change font-size to 16px or above Soution 2: using javascript if(navigator.userAgent.indexOf('iPhone') > -1 ) { document .querySe
阅读全文
摘要:What this refer to? function regularFunction() { this // Global scope } const obj = { regularFunction() { this // The object on which the method is ca
阅读全文
摘要:Once run in async await, the rest of the function body will be push to Microtask Queue console.log(3) Order: 2 3 4 1
阅读全文
摘要:What gets logged when clicking button? <div id="outer"> <div id="inner"> <button id="btn">Click me!</button> </div> </div> const outer = document.getE
阅读全文
摘要:Layout: This step invovles determining the geometry of the page. The browser calculates where each element will be on the screen, considering factors
阅读全文
摘要:JavaScript, the programming language of the web, is often praised for its ability to handle memory management automatically. The JavaScript engine's g
阅读全文
摘要:DOM (Documnet Object Model) Tree: When a web page is loaded, the browser reads the HTML and builds the DOM tree. The DOM is a tree-like structure that
阅读全文
摘要:normal script, without async defer: Script fetched and executed immediately, before browser continues parsing the page (It stops HTML parsing). If the
阅读全文