本文介绍了ECMAScript 6在对象解构中扩展运算符。支持TypeScript和Babel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下有效的ECMAScript 6是否有效?
它似乎得到最新版本的Babel的支持,但它不是通过TypeScript。
我找不到任何适用于这种情况的ES6引用。

  var a = {foo:'foo' }; 
var b = {... a};


解决方案

不,这是无效的ECMAScript 6. ES6只支持功能参数和数组解构中的休息语法,并在函数调用和数组构造中扩展语法。

Babel确实实现了作为。您不应该使用此功能,它可能会随时中断。


Is the following valid ECMAScript 6?It seems to be supported by the latest version of Babel but it isn't by TypeScript.I couldn't find any ES6 references dealing with this case.

var a = { foo : 'foo' };
var b = { ...a };
解决方案

No, this is not valid ECMAScript 6. ES6 does only support rest syntax in function parameters and array destructuring, and spread syntax in function calls and array construction.

Babel does implement the objectRestSpread ES7 proposal as a experimental plugin. You shouldn't use this feature, it may break at any time.

这篇关于ECMAScript 6在对象解构中扩展运算符。支持TypeScript和Babel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 09:26