JavaScript ES2025: இன்றே பயன்படுத்தத் தொடங்கலாம் புதிய அம்சங்கள்
ES2025 Pipe operator, Records & Tuples, Pattern Matching போன்ற உற்சாகமூட்டும் அம்சங்களை கொண்டு வருகிறது. எது ship ஆகிறது மற்றும் எது proposal stage-ல் உள்ளது என்பதை அறிந்து கொள்ளுங்கள்.
JavaScript ES2025: புதிய அம்சங்கள்
JavaScript தொடர்ந்து வளர்ந்து வருகிறது. ES2025 (அதிகாரப்பூர்வமாக ES16) பல உற்சாகமூட்டும் அம்சங்களை கொண்டு வருகிறது.
1. Pipe Operator (|>)
Pipe operator உங்களை function calls-ஐ readable left-to-right flow-ல் chain செய்ய அனுமதிக்கிறது. Nested parentheses தேவையில்லை!
// Pipe இல்லாமல்
const result = capitalize(reverse(trim(input)));
// Pipe உடன்
const result = input
|> trim
|> reverse
|> capitalize;2. Records மற்றும் Tuples
Objects மற்றும் arrays-ன் immutable versions. இவை # prefix பயன்படுத்துகின்றன மற்றும் default ஆக deeply frozen ஆகும்.
const record = #{ name: "w3primecode", lang: "hi" };
const tuple = #[1, 2, 3, 4];
// Deep equality வேலை செய்கிறது!
#{ a: 1, b: 2 } === #{ a: 1, b: 2 }; // true
#[1, 2, 3] === #[1, 2, 3]; // true3. Pattern Matching
Switch-ன் மேம்படுத்தப்பட்ட பதிப்பு. Object shapes, arrays, மற்றும் patterns-ஐ match செய்யுங்கள்.
match (response) {
{ status: 200, data } => renderData(data),
{ status: 404 } => showNotFound(),
{ status: >= 500 } => showServerError(),
_ => showUnknownError()
}4. Array.prototype.group()
Array items-ஐ key மூலம் group செய்யுங்கள். reduce எழுதுவதை விட சிறந்தது.
const posts = [
{ title: "CSS Tips", category: "css" },
{ title: "HTML Guide", category: "html" },
{ title: "More CSS", category: "css" },
];
const grouped = posts.group(p => p.category);
// { css: [...], html: [...] }5. Array.prototype.findLast() மற்றும் findLastIndex()
Array-ஐ reverse செய்யாமல் last matching element-ஐ கண்டுபிடியுங்கள்.
const lastEven = [1, 2, 3, 4, 5].findLast(n => n % 2 === 0); // 46. Object.hasOwn()
Object.prototype.hasOwnProperty.call()-ஐ விட பாதுகாப்பானது.
const obj = Object.create(null);
obj.key = "value";
Object.hasOwn(obj, "key"); // true
// obj.hasOwnProperty("key") பிழை அளிக்கும்!7. Error Cause
Context உடன் errors-ஐ chain செய்யுங்கள். Debugging-க்கு சிறந்தது.
try {
await fetchData();
} catch (err) {
throw new Error("Failed to load user", { cause: err });
}8. structuredClone()
Hacks இல்லாமல் objects-ஐ deep clone செய்யுங்கள் (Dates, Maps, Sets உட்பட).
const original = { date: new Date(), nested: { a: 1 } };
const copy = structuredClone(original);9. Top-level Await
ES modules-ன் top level-ல் await பயன்படுத்துங்கள். IIFE wrapper தேவையில்லை.
// module.mjs
const data = await fetch('/api/data').then(r => r.json());
export default data;10. Array.prototype.at()
Python போல negative indexing.
const arr = [10, 20, 30, 40];
arr.at(-1); // 40
arr.at(-2); // 30Browser Support
| Feature | Chrome | Firefox | Safari |
|---|---|---|---|
| Array.group | ✅ | ✅ | ✅ |
| findLast | ✅ | ✅ | ✅ |
| Object.hasOwn | ✅ | ✅ | ✅ |
| Error cause | ✅ | ✅ | ✅ |
| structuredClone | ✅ | ✅ | ✅ |
| Top-level await | ✅ | ✅ | ✅ |
| Array.at | ✅ | ✅ | ✅ |
| Pipe operator | ⚠️ | ⚠️ | ⚠️ |
| Records & Tuples | ⚠️ | ⚠️ | ⚠️ |
| Pattern matching | ⚠️ | ⚠️ | ⚠️ |
⚠️ = இன்னும் proposal stage-ல் உள்ளது, transpilation தேவைப்படலாம்
முடிவுரை
இந்த அம்சங்களில் பெரும்பாலானவை ஏற்கனவே modern browsers-ல் உள்ளன. Pipe மற்றும் Pattern Matching போன்ற cutting-edge proposals-க்கு, transpile செய்ய Babel அல்லது TypeScript பயன்படுத்துங்கள். group(), findLast(), மற்றும் structuredClone()-ஐ இன்றே பயன்படுத்தத் தொடங்குங்கள் — உங்கள் code நன்றி கூறும்.