随笔分类 - Javascript
摘要:// loop function demo1() { // before loop beforeLoopCode; for (initCode; conditionCode; stepChangeCode) { loopCode } postCode } // recursive function
阅读全文
摘要:class MemoizeMap { constructor() { this._map = new Map(); this._weakMap = new WeakMap(); } _isObject(v) { return typeof v "object" && v !== null; } se
阅读全文
摘要:Promise.myAll = function (promises) { let res, rej; const p = new Promise((resolve, reject) => { res = resolve; rej = reject; }); let i = 0; let resul
阅读全文
摘要:Function.apply.myCall = function (ctx, ...args) { ctx = ctx null || ctx undefined ? globalThis : Object(ctx); const fn = this; const key = Sybmol("fn"
阅读全文
摘要:For Javascript Object, you cannot assume the order of Object property the same as the order of adding those property. The actual order follow this rul
阅读全文
摘要:Proxy The Proxy object enables you to create a proxy for another object, which can intercept and redefine fundamental operations for that object. So w
阅读全文
摘要:[] + [] Answer: "" Both arrays ([]) are first converted to their string representations before the + operator is applied. In JavaScript, arrays are co
阅读全文
摘要:const obj = { a: 1, b: 2, c: { d: 1, e: 2, }, }; function isObject(val) { return val !== null && typeof val "object"; } function observe(obj) { const
阅读全文
摘要:const obj = { a: 1, b: 2, c: { a: 1, b: 2, }, }; function isObject(val) { return val !== null && typeof val "object"; } function observe(obj) { for (l
阅读全文
摘要:As we know we can read property value from an object as so: const obj = {} obj.xxxx; obj[xxxx]; So what's the difference between those two? obj.x ECMA
阅读全文
摘要:Function.prototype.myBind = function (ctx, ...args) { const fn = this; return function (...subArgs) { console.log(new.target); const allArgs = [...arg
阅读全文
摘要:The new.target meta-property lets you detect whether a function or constructor was called using the new operator. In constructors and functions invoke
阅读全文
摘要:Eliminate the ambiguity of the function What ambiguity means? Normally a function can do two things 1. Instruction sequence 2. Contruction function a(
阅读全文
摘要:async function asy1() { console.log(1) await asy2() console.log(2) } asy2 = async () => { // First set // await setTimeout((_) => { // Promise.resolve
阅读全文
摘要:We often see circular dependency, why it's a problem, why we should avoid it and hwo to avoid it? Let's see any example first // main.js import A from
阅读全文
摘要:function observe(obj) { for (const key in obj) { let internalValue = obj[key]; const funs = new Set() Object.defineProperty(obj, key, { configurable:
阅读全文
摘要:Let's say we have a Vue application that renders many heavy components on the first load. The problem we're facing is a long white screen period while
阅读全文
摘要:export const isPromiseLike = <T>(value: PromiseLike<T>) => value !== null && (typeof value 'object' || typeof value 'function') && typeof value.then '
阅读全文
摘要:export const isAsyncFunction = (fn: Function) => fn[Symbol.toStringTag] 'AsyncFunction'; // isAsyncFunction(() => {}) // false // isAsyncFunction(() =
阅读全文
摘要:.callmethod exits on any function, which will refer to Function.prototype.call for example: console.log.call Function.prototype.call // call Also it m
阅读全文