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

推荐订阅源

N
News | PayPal Newsroom
P
Proofpoint News Feed
Cyberwarzone
Cyberwarzone
C
Cisco Blogs
SecWiki News
SecWiki News
Know Your Adversary
Know Your Adversary
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Vercel News
Vercel News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
NISL@THU
NISL@THU
WordPress大学
WordPress大学
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Threat Research - Cisco Blogs
AI
AI
Simon Willison's Weblog
Simon Willison's Weblog
Security Archives - TechRepublic
Security Archives - TechRepublic
有赞技术团队
有赞技术团队
L
LINUX DO - 热门话题
Hacker News: Ask HN
Hacker News: Ask HN
V
V2EX
G
GRAHAM CLULEY
TaoSecurity Blog
TaoSecurity Blog
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
F
Fortinet All Blogs
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
Latest news
Latest news
The Hacker News
The Hacker News
aimingoo的专栏
aimingoo的专栏
T
Troy Hunt's Blog
S
Schneier on Security
I
Intezer
Google DeepMind News
Google DeepMind News
A
Arctic Wolf
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threatpost
爱范儿
爱范儿
The Register - Security
The Register - Security
S
SegmentFault 最新的问题
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
宝玉的分享
宝玉的分享
Recent Commits to openclaw:main
Recent Commits to openclaw:main
美团技术团队
B
Blog RSS Feed

wuxinhua.com Blog | RSS Feed

写作者与不写作者:AI 时代的思考分水岭 - wuxinhua.com 一文搞懂 Prompt Engineering - wuxinhua.com #30 AI 颠覆我对传统创业团队的认知 - wuxinhua.com 前端面试系列 - 手写代码 - wuxinhua.com #29 微软与 OpenAI 合作内幕 - wuxinhua.com #28 离 30 岁越来越远 - wuxinhua.com Add AI Chatbox to your VitePress document site - wuxinhua.com Building a Blog Subscription and Pusher with AirCode and Resend - wuxinhua.com #27 创始人是公司灵魂的守护者 - wuxinhua.com 快速上手 Midjourney AI 做图 - wuxinhua.com Building your first Discord ChatGPT Bot - wuxinhua.com ChatGPT 机器人系列 - 用 JavaScript,五分钟将 Siri 接入 ChatGPT - wuxinhua.com ChatGPT 机器人系列 - 用 JavaScript 五分钟开发一个飞书 ChatGPT 机器人 - wuxinhua.com ChatGPT 机器人系列 - 用 JavaScript 开发企业微信 ChatGPT 聊天应用 - wuxinhua.com #26 SVB 硅谷银行为什么倒闭 - wuxinhua.com #25 人人都可以成为 AI 工程师 - wuxinhua.com #24 关注你身体的变化 - wuxinhua.com #23 Be positive - wuxinhua.com 前端面试系列 - 前端八股文 - wuxinhua.com #22 AI 在殖民,社交媒体在衰退 - wuxinhua.com #21 我了解到的新冠后遗症 - wuxinhua.com #20 关于死亡和告别 - wuxinhua.com #19 永远无法准备好 - wuxinhua.com macOS 前端开发环境配置 - wuxinhua.com 我的 Newsletter 321来信 - wuxinhua.com Node.js 包管理及 npm 依赖安装机制 - wuxinhua.com 知识的碎片(2021) - wuxinhua.com 放弃 newsfeed 拥抱 newsletter - wuxinhua.com 混迹于 Clubhouse 两周后的一些想法🤔 - wuxinhua.com 认识Docker - wuxinhua.com 知识的碎片(2020) - wuxinhua.com 初探 Web Components - wuxinhua.com Linux 命令行之 Crontab - wuxinhua.com 今年看的书📚(2019) - wuxinhua.com 适配 iOS 13 - wuxinhua.com React Native 新手常见问题及体验总结 - wuxinhua.com Flexbox布局完全指南 - wuxinhua.com 今年看的书📚(2018) - wuxinhua.com 《从0到1 - 如何创造未来 》书评 - wuxinhua.com www背后的故事 - wuxinhua.com contenteditable 踩坑记 - wuxinhua.com Good Code vs Bad Code in Golang - wuxinhua.com 关于React的几道面试题 - wuxinhua.com SVG动画实践 - wuxinhua.com 今年看的书📚(2017) - wuxinhua.com 对比几种常见的排序算法 - wuxinhua.com React服务端渲染(SSR)初探 - wuxinhua.com 从面试题“输入URL...发生了什么”学到的(下) - wuxinhua.com 从面试题“输入URL...发生了什么?”学到的(上) - wuxinhua.com ES6(ECMAScript 6.0)新特征 - wuxinhua.com 对React-redux中connect方法的理解 - wuxinhua.com 我的 RSS 订阅列表 - wuxinhua.com 《空谷幽兰》书评 - wuxinhua.com 你可能不知道git rerere - wuxinhua.com webpack v2升级踩坑笔记 - wuxinhua.com
ES10(ECMAScript2019)特征预览 - wuxinhua.com
2019-04-27 · via wuxinhua.com Blog | RSS Feed

2019 年 1 月末的时候,ECMA TC39 终于确定了 ES2019 版 JavaScript 的新增内容,ES2019 将会增加 arrays, objects, strings, symbols, try/catch 和 JSON 等方面的特征。

Array#{flat,flatMap}

Array 的原型链上增加了新的两个方法:Array.flat(tc39 proposal) 和 Array.flat(tc39 proposal) 能够进行扁平化多维数组:

1var arr = [1, 2, 3, [4, 5, 6, [7, 8, 9, [10, 11, 12]]]]; 2arr.flat(); // [1, 2, 3, 4, 5, 6, Array(4)]

等同于arr.flat(1)

1arr.flat(1); // [1, 2, 3, 4, 5, 6, Array(4)]

逐个展开:

1arr.flat().flat() // [1, 2, 3, 4, 5, 6, 7, 8, 9, Array(3)] 2arr.flat().flat().flat() // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] 3// 超出可扁平化范围结果保持不变 4arr.flat().flat().flat().flat() // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] 5// 当然也等同于 6arr.flat(2); // [1, 2, 3, 4, 5, 6, 7, 8, 9, Array(3)] 7arr.flat(3); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] 8arr.flat(Infinity); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

flatMap()方法类似于数组的map方法,对数组的每一项使用传入的function,结果得到的是扁平化的数组,值得注意的是所有的结果将不会折叠,而是展示为一维数组:

1var arr = [1, 2, 3, [4, 5, 6, [7, 8, 9, [10, 11, 12]]]]; 2arr.flatMap(item => item * 2); // [2, 4, 6, NaN] 3// map vs flatMap 4var arr = [1, 2, 3, 4]; 5arr.map(item => [item, item * 2]); // [Array(2), Array(2), Array(2), Array(2)] 6arr.flatMap(item => [item, item * 2]); // [1, 2, 2, 4, 3, 6, 4, 8]

BigInt

BigInt 是一个新的类型,用于表达大于 2^53 的值

Object.fromEntries

我们已经知道可以使用Object.entries返回对象自身可枚举属性键值对数组,而Object.fromEntries(tc39 proposal)则可以看做是这一过程的逆转,用数组返回可枚举对象,loadash里提供了_.fromPairs(pairs)类似的方法。

1var obj = { foo: 1, baz: 2 }; 2Object.entries(obj); //  [Array(2), Array(2)] =>  [['foo', 1], ['baz', 2]] 3Object.fromEntries([['foo', 1], ['baz', 2]]); // {foo: 1, baz: 2}

String#{trimStart,trimEnd}

这两个方法应该是弥补trim的不足,trim会直接把两头的空白均移除,trimStart()方法用于移除字符串开头的空白,trimEnd()用于移除字符串末尾的空白。

1var str = ' ECMAScript 2019 '; 2str.trim(); // "ECMAScript 2019" 3str.trimStart(); // "ECMAScript 2019 "

Symbol.prototype.description

Symbol类型增加description属性,返回Symbol对象的可选描述的字符串。

1Symbol('ECMAScript2019').description; // ECMAScript2019 2typeof Symbol('ECMAScript2019').description; // string 3Symbol('').description; // "" 4Symbol().description; // undefined

try { } catch {} // optional binding

opitionam bindingtc39 proposal catch参数可选。经常会有这种情况,并没有使用到catch内的参数:

1try { 2 // do something when success 3} catch (unused) { 4 // do something when error 5} 6

之后可以这样写:

1try { 2 // ... 3} catch { 4 // ... 5}

JSON ⊂ ECMAScript

JSON也有两处的优化:行分隔符(U+2028)和段分隔符(U+2029)符号现在允许在字符串文字中,与JSON匹配。 以前,这些符号在字符串文字中被视为行终止符,因此使用它们会导致SyntaxError异常。


优化JSON.stringify

改进了JSON.Stringify()方法,防止返回不符合规范Unicode字符串。

1// 之前 2JSON.stringify('\uD800'); // '"�"' 3// 之后 4JSON.stringify('\uD800'); // '"\\ud800"'

Function.prototype.toString

toString()方法现在能返回源代码字符串,包括空行和注释:

1function /* a comment */ foo () {} 2foo.toString() // "function /* a comment */ foo () {}" 3

Array.prototype.sort

ECMAScript2019版的sort会确保Array.sort方法是稳定的。

之前总结的 ES6 新特征点这 => ES6(ECMAScript 6.0)新特征