【Java】读取文件内容InputStream
/** * 读取文件内容 * @return String * @author xinhui.chen * @updateTime 2022/9/28 */ private String readFromInputStream(InputStream inputStream) throws IOException { StringBuilder r…
【JavaScript】手写深拷贝
要点: 递归 判断类型 检查环 不拷贝原型上的属性 const deepClone = (a, cache) => { if(!cache){ cache = new Map() // 缓存不能全局,最好临时创建并递归传递 } if(a instanceof Object) { // 不考虑跨 iframe if(cache.get(a)) …
【JavaScript】手写 Promise.all
要点: 知道要在 Promise 上写而不是在原型上写 知道 all 的参数(Promise 数组)和返回值(新 Promise 对象) 知道用数组来记录结果 知道只要有一个 reject 就整体 reject Promise.prototype.myAll Promise.myAll = function(list){ const results…
【JavaScript】手写AJAX
//什么是Ajax? async JavaScript and XML(JSON) let xhr = new XMLHttpRequest(); xhr.open('GET','/requestHttpDemo'); // xhr.onload = () => { // console.log(�…
【JavaScript】手写防抖
// 概念:回城被打断 let debounce = (fn, time, asThis) => { let timer = null; return (...args) => { if (timer) { clearTimeout(timer) } timer = setTimeout(() => { fn.call(asThi…
【JavaScript】手写节流
// 概念:触发CD let debounce = (fn, time, asThis) => { let cooldown = false; let timer = null; return (...args) => { if (cooldown) { return; } fn.call(asThis, ...args) cooldo…