Object.freeze
Object.freeze และ as const ทำให้ objects immutable แต่ต่างกัน - Object.freeze เป็น runtime freeze ส่วน as const เป็น compile-time type only
เปรียบเทียบ
Section titled “เปรียบเทียบ”| Feature | Object.freeze | as const | readonly |
|---|---|---|---|
| Runtime protection | Yes | No | No |
| Type narrowing | No | Yes (literal) | Partial |
| Deep freeze | No (shallow) | Yes | Manual |
| Arrays | Partially | Yes | Yes |
เข้าสู่ระบบเพื่อดูเนื้อหาเต็ม
ยืนยันตัวตนด้วยบัญชี Google เพื่อปลดล็อกบทความทั้งหมด
Login with Google