理解 this[instruction](...[arg])
- 在 JavaScript 中,可以使用方括号(
[]
)通过字符串来访问对象的属性,而不用点(.
)操作符。
const methodName = "startMeeting"; this[methodName](); // 等同于 this.startMeeting();
...[arg]
是使用展开操作符,将数组元素作为函数参数传递。
const args = [2, 3]; someFunction(...args); // 等同于 someFunction(2, 3);
什么是 zod 模式?
- Schema + Validation + Parsing
import { z } from 'zod'; // 定义用户模式 const UserSchema = z.object({ id: z.number(), name: z.string(), email: z.string().email(), age: z.number().optional(), }); // 验证和解析示例数据 const userData = { id: 1, name: "Alice", email: "[email protected]", age: 30, }; try { // 解析并验证数据 const user = UserSchema.parse(userData); console.log(user); // 解析后的数据 } catch (e) { console.error(e.errors); // 验证失败时的错误信息 }
TS 中 unknown 和 any 的区别?
unknown
是 any
的更安全替代,鼓励在不确认类型时使用 unknown
来强迫类型检查,以确保类型安全。使用
any
:function logValue(value: any) { console.log(value.toUpperCase()); // 这里假设 value 是字符串,但如果不是,运行时会报错 } logValue("hello"); // 正常工作 logValue(42); // 运行时错误:value.toUpperCase is not a function
使用
unknown
:function logValue(value: unknown) { if (typeof value === "string") { console.log(value.toUpperCase()); // 只有在确认 value 为字符串时才调用 toUpperCase } else { console.log("Value is not a string"); } } logValue("hello"); // 正常工作 logValue(42); // 输出:Value is not a string
其中,
unknown
强制在使用 value
之前进行类型检查,从而防止运行时错误。类型检查可以用 typeof,instanceof,也可以用 zod 的 parse 方法。SSH 连不上?
- 可能会遇到这个问题
luke@hela:~/chromium/src$ ssh [email protected] @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that a host key has just been changed. The fingerprint for the ED25519 key sent by the remote host is SHA256:ukhqthyVargmIqFHOkekWeJztFQXqJqeGAdQO5TSDdU. Please contact your system administrator. Add correct host key in /home/luke/.ssh/known_hosts to get rid of this message. Offending ED25519 key in /home/luke/.ssh/known_hosts:4 remove with: ssh-keygen -f "/home/luke/.ssh/known_hosts" -R "192.168.50.177" ED25519 host key for 192.168.50.177 has changed and you have requested strict checking. Host key verification failed.
解决办法:
ssh-keygen -R "192.168.50.177"
没有开发者工具怎么调试前端?
box-shadow 可以用来调试,不会影响盒子的大小
Comments