/images/avatar.png

A Clean Blog

React 中的 "this"

0 简介 这里写的 React 中的 this 问题,其实不是 React 特有,而是 JavaScript 的,我这里仅介绍 React 中常见的情况。 this 简而言之就是:Function call this 更详细的前因后果,我可

受控组件和非受控组件

1 受控组件 使用 React 时, <input> 的 value 存储在 Component 的 state 里,value 受到 React 的 state 控制,只有 state 改变,渲染出来的 DOM 的 value 才改变。 2 非受控元素 指 value 存储在 DOM 里,例如 <input> 的

重构 if-else 或 switch 成 table

if-else❌ 1 2 3 4 5 6 7 if (season === "summer") { return "It's 30, hot!"; } else if (season === "winter") { return "It's 2, cold!"; } else { return "It's 20, good!"; } switch❌ 1 2 3 4 5 switch (season) { case "summer": return "It's 30, hot!"; case "winter": return "It's 2, cold!";

实用库 FakerJS

1 简介 faker.js - generate massive amounts of fake data in the browser and node.js. faker.js - 在浏览器和 node.js 中生成大量假数据。 在开发中我们经常需要数据的临时占位,例如头像、背景图片、邮箱、电话等等数据

JavaScript 打字效果

1 打字效果 我要把下面的一段原始文本,用 JavaScript 实现打字机效果的动画。 1 2 3 4 5 6 /* Draw a Spider */ .spider { width: 400px; margin-left: auto; margin-right: auto; } 效果如图: 纯文本的打字效果typewr