Is it statistically safe to use proposals in Stage 3 of ECMA?

时间秒杀一切 提交于 2019-12-11 05:07:13

问题


Background

I am referring to the ... operator. Many people like and support the idea of doing the following:

const obj = { "hello": 1 };
const obj2 = { "world": 2, ...obj };

Problem

I personally like this syntax over the typical Object.assign but recently when I started using it in my project I had this eslint error:

Object Spread - Parsing error: Unexpected token

The solution to this can be seen in the following links:

  • https://github.com/eslint/eslint/issues/4052
  • https://eslint.org/docs/1.0.0/user-guide/configuring

The problem here is that to use such syntax we need to enable the experimentalObjectRestSpread flag on eslint. This flag is accompanied by the following warning:

experimentalObjectRestSpread - enable support for the experimental object rest/spread properties (IMPORTANT: This is an experimental feature that may change significantly in the future. It’s recommended that you do not write rules relying on this functionality unless you are willing to incur maintenance cost when it changes.)

After verifying the proposal I realised it is in Stage 3: https://github.com/tc39/proposal-object-rest-spread

More information on the different stages can be seen here:

  • http://2ality.com/2015/11/tc39-process.html

Question

  • What are probabilities of backwards compatibility changes in S3?
  • How many proposals have been withdrawn at S3 ?

回答1:


What are probabilities of backwards compatibility changes in S3?

Low without returning to Stage 2 (see next question).

How many proposals have been withdrawn at S3 ?

It's rare, but it does happen. For instance, decorators was Stage 3 for some time but has been rolled back to Stage 2. Similarly, class fields were at Stage 3 but moved back to Stage 2 in November (and have since been split [again], where the Class Public Instance Fields & Private Instance Fields proposal went back to Stage 3 again, leaving Static class fields and private static methods at Stage 2).

You can get an idea of how things move by reviewing the history on the README.md for https://github.com/tc39/proposals. It can be a bit of a pain, though.

Is it statistically safe to use proposals in Stage 3 of ECMA?

It depends on what you mean by "statistically safe." If you want a high degree of certainty, restrict yourself to Stage 4.

Specifically in regard to object rest/spread, it's implemented (not behind a flag) in current versions of V8 shipping in Chrome and SpiderMonkey shipping in Firefox. Try it here:

const a = {answer: 42};
const b = {question: "Life, the Universe, and Everything", ...a};
console.log(b);

On the first day of the TC39 meeting in November, the status update was:

KCL: Is Object spread possible to make it into es2018?

BT: If someone can make a PR and get it on the January agenda then we can put it in.

...which sounds like Stage 4 in January is likely.



来源:https://stackoverflow.com/questions/48149745/is-it-statistically-safe-to-use-proposals-in-stage-3-of-ecma

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!