随笔分类 - Javascript
摘要: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
阅读全文
摘要:function timeout(time) { return new Promise((resolve) => { setTimeout(resolve, time); }); } class ParalleTask { constructor(paralleCount = 2) { this.t
阅读全文
摘要:export const randomColor = () => { return "#" + Math.random().toString(16).substring(2, 8).padEnd(6, '0') } export const randomString = (len: number)
阅读全文
摘要:In this post, we’ll explore an intriguing use of JavaScript’s Proxy and Symbol.toPrimitive to perform cumulative operations, mimicking a numeric conte
阅读全文
摘要:// Object.prototype[Symbol.iterator] = function() { // return Object.values(this)[Symbol.iterator](); // } Object.prototype[Symbol.iterator] = functio
阅读全文
摘要:One way data binding, the parent component pasing data through v-modelto child component, if child modify the data, v-modelwill take care emit the cha
阅读全文
摘要:/** * Big integer sum * Using strings to represent big integers * @param {string} a * @param {string} b * @returns {string} */ function bigIntSum(a, b
阅读全文
摘要:When you use ChatGPT, the response comes in stream, so that it can appears on screen whenever data come back from server, we don't need to wait all da
阅读全文
摘要:Try option 1: Promise Promise running in Microtask queue, and rendering should wait until the queue is empty; If you have a large number of time-consu
阅读全文
摘要:const fetch = () => new Promise((res) => { setTimeout(() => res({ user: 'zhen' }), 1150) }) globalThis.fetch = fetch async function getUser() { return
阅读全文
摘要:For this code, try to not modify the code itself but mutate obj var o = (function () { var obj = { a: 1, b: 2, }; return { get: function (k) { return
阅读全文
摘要:The basic interpolatefunction we can create: function interpolate(str, params) { let names = Object.keys(params); // ["title", "description"] let valu
阅读全文
摘要:Let's say we have a web component: import { getProductById } from "../services/Menu.js"; import { addToCart } from "../services/Order.js"; export defa
阅读全文
摘要:// memento.js import { TodoList } from "./classes.js"; export const TodoHistory = { history: [], push(state) { if (state) { // always push a new Set t
阅读全文
摘要:Refer to: https://stately.ai/docs/actor-model What defines an “actor”? Actors are independent “live” objects that can communicate with each other via
阅读全文
摘要:Problem to Solve Reparesent a value that is immutable and distinct from other objects based on its properties rather than its identity. Solution Creat
阅读全文