tc39 / proposal-class-public-fields

Stage 2 proposal for public class fields in ECMAScript
https://tc39.github.io/proposal-class-public-fields/
488 stars 25 forks source link

do errors thrown in initialisers cause an abrupt completion of construction? #10

Closed michaelficarra closed 8 years ago

michaelficarra commented 9 years ago
class A {
  b = (_ => { throw 0; })();
  c = f();
  constructor() {
    g();
  }
}

Is f() evaluated? Is g()? Does new A throw? If not, what is the value of new A().b?

fatfisz commented 8 years ago

f() will be evaluated when new A() is executed. The same for g(). new A should throw when b's initializer is executed.

Amirite?

jeffmo commented 8 years ago

new A will throw and neither f(), nor the constructor() method itself will be evaluated here.

michaelficarra commented 8 years ago

So new A is guaranteed to evaluate the initialiser of b before the initialiser of c and before the constructor body?

jeffmo commented 8 years ago

Yes: https://github.com/jeffmo/es-class-static-properties-and-fields#instance-field-initialization-process

intended to run once for each field in the order they are declared