You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constname=Symbol('My name is axuebin');console.log(name.description);// My name is axuebinconsole.log(name.description==='My name is axuebin');// My name is axuebin
Previous
我们知道,Symbol 的描述只被存储在内部的 [[Description]],没有直接对外暴露,我们只有调用 Symbol 的 toString() 时才可以读取这个属性:
constname=Symbol('My name is axuebin');console.log(name.toString());// Symbol(My name is axuebin)console.log(name);// Symbol(My name is axuebin)console.log(name==='Symbol(My name is axuebin)');// falseconsole.log(name.toString())==='Symbol(My name is axuebin)');// true
ES2019
tc39 Finished Proposals
从表中可以看到已经有多个特性加到了 ES2019 中。
新特性
Optional catch binding
https://github.com/tc39/proposal-optional-catch-binding
将
err
变成optional
的,可以省略catch
后的 括号和错误对象:Previous
之前
try...catch
是这样的:比如:
有的时候我们只需要捕获错误但是无需知道错误信息,
err
就显得没必要的。JSON superset
https://github.com/tc39/proposal-json-superset
允许 未转义的
U + 2028
行分隔符和U + 2029
段分割符直接出现在字符串中,不会出现异常。Previous
之前,JSON的某些字符
\u2028
\u2029
会导致 Javascript 语法错误。我们的解决方法是对
\u2028
\u2029
进行转义,比如:Symbol.prototype.description
https://github.com/tc39/proposal-Symbol-description
Symbol.prototype.description | MDN
可以通过
description
方法获取Symbol
的描述:Previous
我们知道,
Symbol
的描述只被存储在内部的[[Description]]
,没有直接对外暴露,我们只有调用Symbol
的toString()
时才可以读取这个属性:在执行
console.log(name)
的时候也打印了描述信息,是因为这里隐式地执行了toString()
,在代码里这样是不行的。Function.prototype.toString revision
https://github.com/tc39/Function-prototype-toString-revision
现在
foo.toString()
可以返回精确字符串,包括空格和注释等。Object.fromEntries
https://github.com/tc39/proposal-object-from-entries
Object.fromEntries() | MDN
该方法把键值对列表转换为一个对象,可以看作是
Object.entries()
的反向方法。和
lodash
的_.fromPairs
具有一样的功能。Well-formed JSON.stringify
https://github.com/tc39/proposal-well-formed-stringify
更友好的
JSON.stringify
,对于一些超出范围的Unicode
,为其输出转义序列,使其成为有效Unicode
,Previous
String.prototype.{trimStart,trimEnd}
https://github.com/tc39/proposal-string-left-right-trim
String.prototype.trimStart() | MDN
String.prototype.trimEnd() | MDN
分别去除字符串前后的空格,生成新的字符串。
Array.prototype.{flat,flatMap}
https://github.com/tc39/proposal-flatMap
Array.prototype.flat() | MDN
Array.prototype.flatMap() | MDN
还记得这样一道笔试题么,给你一个多维数组,把它拍平!
是不是很方便...
暂时就这些啦
The text was updated successfully, but these errors were encountered: