惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
D
Docker
云风的 BLOG
云风的 BLOG
F
Fortinet All Blogs
F
Full Disclosure
H
Hackread – Cybersecurity News, Data Breaches, AI and More
P
Proofpoint News Feed
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
L
LangChain Blog
H
Help Net Security
B
Blog
T
Tailwind CSS Blog
V
V2EX
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
Recent Announcements
Recent Announcements
aimingoo的专栏
aimingoo的专栏
美团技术团队
A
About on SuperTechFans
C
Cybersecurity and Infrastructure Security Agency CISA
K
Kaspersky official blog
I
InfoQ
Project Zero
Project Zero
I
Intezer
Google DeepMind News
Google DeepMind News
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
T
Threat Research - Cisco Blogs
Last Week in AI
Last Week in AI
C
Cyber Attacks, Cyber Crime and Cyber Security
G
GRAHAM CLULEY
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AWS News Blog
AWS News Blog
Spread Privacy
Spread Privacy
S
Securelist
Recorded Future
Recorded Future
D
Darknet – Hacking Tools, Hacker News & Cyber Security
博客园 - 叶小钗
S
Security Affairs
Blog — PlanetScale
Blog — PlanetScale
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
月光博客
月光博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
The Hacker News
The Hacker News

Jack Pu's Blog (蒲小花的博客-ポーのブログ)

拥有孩子的得与失 大事件 记一次警察访谈 重庆 一句抵一万句 The Plan of 2026 2025 2022 年往事 小青橙第一次急疹 OTT 开发的挑战 我了解的美国 VS 我体验的美国 国庆小记 开学第一课 为什么 Android Webview 不支持 L1 级别的 Widevine DRM 安全级别 夏末
【DRAFT】ES2025 的语法糖科普
Jack Pu · 2025-09-30 · via Jack Pu's Blog (蒲小花的博客-ポーのブログ)

不知不觉 ES2025 都快推出了,这里分享一些比较有趣的用法。

Time API

更新的时间API

// Simplified date creation
const now = Temporal.now();
const birthday = @2024-01-15; // New date literal syntax
const meeting = @2024-12-25T10:30:00[Asia/Shanghai];

// Syntactic sugar for date/time arithmetic
const nextWeek = now + 7.days;
const lastMonth = now - 1.month;
const deadline = meeting + 2.hours + 30.minutes;

// Time range syntax
const workingHours = @09:00..17:00;
const workingDays = @Monday..Friday;

console.log(workingHours.contains(@14:30)); // true
console.log(workingDays.contains(Temporal.now().dayOfWeek)); // Check if today is a working day

Record & Tuple

对不可修改数据的支持

// Record: immutable object
const userRecord = #{
  id: 1,
  name: "Zhang San",
  email: "zhangsan@example.com"
};

// Tuple: immutable array
const coordinates = #[10, 20, 30];
// Strict equality check
const user1 = #{ id: 1, name: "Zhang San" };
const user2 = #{ id: 1, name: "Zhang San" };
console.log(user1 === user2); // true!

// Nested structures
const complexData = #{
  users: #[
    #{ id: 1, name: "Zhang San" },
    #{ id: 2, name: "Li Si" }
  ],
  config: #{
    theme: "dark",
    language: "zh-CN"
  }
};

Decimal Data Type

解决十进制精度问题来了

// Old approach: precision loss
console.log(0.1 + 0.2); // 0.30000000000000004

// New approach: precise calculation
console.log(0.1m + 0.2m); // 0.3m
// A blessing for financial calculations
const price = 19.99m;
const tax = 0.08m;
const total = price * (1m + tax);
console.log(total); // 21.5892m, perfectly accurate!
// Conversion with Number
const decimalValue = 123.456m;
const numberValue = Number(decimalValue); // 123.456
const backToDecimal = Decimal(numberValue); // 123.456m

Upgraded Import Assertions

增强了导入断言,使模块导入更安全、更灵活

// Importing JSON modules
import config from './config.json' with { type: 'json' };

// Importing CSS modules
import styles from './styles.css' with { type: 'css' };

// Importing WebAssembly modules
import wasmModule from './math.wasm' with { type: 'webassembly' };

// Dynamic import with assertions 
const loadConfig = async (env) => {
  const config = await import(`./config-${env}.json`, { with: { type: 'json' } });
  return config.default;
};

// Conditional import
if (process.env.NODE_ENV === 'development') { import devConfig from './config-dev.json' with { type: 'json' }; }

Template String Enhancements

更强大的字符串模板

// Automatic multi-line indentation handling
const html = html`
<div class="container">
  <h1>${title}</h1>
  <p>${content}</p>
</div>
`; // Indentation handled automatically

// Custom interpolation handling
const sql = sql`
SELECT * FROM users
WHERE age > ${minAge}
AND city = ${city}
`; // Automatically protects against SQL injection


// Internationalized template
const message = i18n`Hello ${name}, you have ${count} new messages`; // Automatically handles locale and pluralization rules

// Styled string
const styledText = css`
color: ${primaryColor};
font-size: ${fontSize}px;
margin: ${margin};
`;

参考

https://medium.com/codeelevation/you-can-write-javascript-like-this-new-es2025-syntactic-sugar-be4081cf5187