ECMAScript 6在对象解构中扩展运算符。支持TypeScript和Babel [英] ECMAScript 6 spread operator in object deconstruction. Support in TypeScript and Babel

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

问题描述

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

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


解决方案

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


似乎被Babel的最新版本


Babel确实实现了 objectRestSpread ES7提案作为实验插件。您不应该使用此功能,它可能会随时中断。


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.

It seems to be supported by the latest version of Babel

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆