随笔分类 -  Javascript

上一页 1 2 3 4 5 6 7 8 ··· 30 下一页
摘要:function timeout(time) { return new Promise((resolve) => { setTimeout(resolve, time); }); } class ParalleTask { constructor(paralleCount = 2) { this.t 阅读全文
posted @ 2024-09-03 21:12 Zhentiw 阅读(15) 评论(0) 推荐(0)
摘要:export const randomColor = () => { return "#" + Math.random().toString(16).substring(2, 8).padEnd(6, '0') } export const randomString = (len: number) 阅读全文
posted @ 2024-09-03 20:35 Zhentiw 阅读(17) 评论(0) 推荐(0)
摘要:In this post, we’ll explore an intriguing use of JavaScript’s Proxy and Symbol.toPrimitive to perform cumulative operations, mimicking a numeric conte 阅读全文
posted @ 2024-08-28 02:16 Zhentiw 阅读(31) 评论(0) 推荐(0)
摘要:// Object.prototype[Symbol.iterator] = function() { // return Object.values(this)[Symbol.iterator](); // } Object.prototype[Symbol.iterator] = functio 阅读全文
posted @ 2024-08-26 00:20 Zhentiw 阅读(10) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2024-08-25 19:51 Zhentiw 阅读(115) 评论(0) 推荐(0)
摘要:/** * Big integer sum * Using strings to represent big integers * @param {string} a * @param {string} b * @returns {string} */ function bigIntSum(a, b 阅读全文
posted @ 2024-08-25 16:05 Zhentiw 阅读(19) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2024-08-25 15:49 Zhentiw 阅读(10) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2024-08-24 16:40 Zhentiw 阅读(25) 评论(0) 推荐(0)
摘要:const fetch = () => new Promise((res) => { setTimeout(() => res({ user: 'zhen' }), 1150) }) globalThis.fetch = fetch async function getUser() { return 阅读全文
posted @ 2024-08-23 19:43 Zhentiw 阅读(16) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2024-08-23 03:47 Zhentiw 阅读(14) 评论(0) 推荐(0)
摘要:The basic interpolatefunction we can create: function interpolate(str, params) { let names = Object.keys(params); // ["title", "description"] let valu 阅读全文
posted @ 2024-08-20 14:49 Zhentiw 阅读(55) 评论(0) 推荐(0)
摘要:Let's say we have a web component: import { getProductById } from "../services/Menu.js"; import { addToCart } from "../services/Order.js"; export defa 阅读全文
posted @ 2024-08-20 14:23 Zhentiw 阅读(17) 评论(0) 推荐(0)
摘要:// memento.js import { TodoList } from "./classes.js"; export const TodoHistory = { history: [], push(state) { if (state) { // always push a new Set t 阅读全文
posted @ 2024-08-19 14:45 Zhentiw 阅读(10) 评论(0) 推荐(0)
摘要:Refer to: https://stately.ai/docs/actor-model What defines an “actor”?​ Actors are independent “live” objects that can communicate with each other via 阅读全文
posted @ 2024-08-14 15:07 Zhentiw 阅读(34) 评论(0) 推荐(0)
摘要:Problem to Solve Reparesent a value that is immutable and distinct from other objects based on its properties rather than its identity. Solution Creat 阅读全文
posted @ 2024-08-14 14:52 Zhentiw 阅读(5) 评论(0) 推荐(0)
摘要:Problem to Solve Share functionality between classes without using inheritance. Solution Create a class containing methods that can be used by other c 阅读全文
posted @ 2024-08-14 14:48 Zhentiw 阅读(8) 评论(0) 推荐(0)
摘要:class ApplicationError extends Error { get name() { return this.constructor.name; } } class DatabaseError extends ApplicationError {} class UserFacing 阅读全文
posted @ 2024-08-11 22:06 Zhentiw 阅读(10) 评论(0) 推荐(0)
摘要:class Product { name; price; constructor(name, price) { this.name = name; try { this.price = price * 1.30; } catch(e) { throw new Error("Product canno 阅读全文
posted @ 2024-08-11 22:03 Zhentiw 阅读(9) 评论(0) 推荐(0)
摘要:Docs: https://webkit.org/blog/6240/ecmascript-6-proper-tail-calls-in-webkit/ /* This is a recursive function without PTC */ function fatorial(n) { if 阅读全文
posted @ 2024-08-07 19:29 Zhentiw 阅读(10) 评论(0) 推荐(0)
摘要:You don't really need to apply a really complex regex for one validation, instead you can combine multi regex together to fulfilll the task. const reg 阅读全文
posted @ 2024-07-08 14:57 Zhentiw 阅读(11) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 8 ··· 30 下一页