美文网首页
Typescript 3.7.2新特性

Typescript 3.7.2新特性

作者: EickL | 来源:发表于2019-12-03 16:29 被阅读0次

请移步到我的Blog,获得更好的阅读体验!本文的链接请点这里

新特性

可选链(Optional Chaining)

let x = foo?.bar.baz();

等效于:

let x = (foo === null || foo === undefined) ?
    undefined :
    foo.bar.baz();

注意:当bazundefined时,仍然会报错,这时需要再次判断baz是否为空:

let x = foo?.bar?.baz?.call(null)
// 这里我使用了call来调用方法

相关文章

网友评论

      本文标题:Typescript 3.7.2新特性

      本文链接:https://www.haomeiwen.com/subject/qtzcgctx.html