babel: Spec compatibility: Calling class constructor functions as function should throw

This is probably very difficult or impossible to achieve. According to the newest draft (rev32), calling a class constructor function like a normal function (basically everything but calling it with new as far as I understand), should throw a TypeError:

class Foo {}
Foo(); // should throw
Foo.call({});  // should throw
Foo.apply({});  // should throw

The spec uses an internal flag on the function object for that.

Not sure we can do anything here, just raising awareness and keep track of it.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 20 (9 by maintainers)

Most upvoted comments

Can you do something like this?

class Dummy extends oldCtor {
  constructor(...args) {
    super(...args);
  }
}

Can you post a code example which throws but shouldn’t?