Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Feb 19, 2018. It is now read-only.
/discussPublic archive
This repository was archived by the owner on Feb 19, 2018. It is now read-only.

CS2 Discussion: Output: Super - CS vs ES6 semantics #68

Closed
@mrmowgli

Description

@mrmowgli

Currently we have classes working in connec's branchpull #4354 (read the comments) - however as we go through the tests and compatibility with ES6 classes there are a lot of edge cases around super. In particular how ES6 (currently) handles super.

The basics of ES and super:

  • super() needs to be called in a constructor forthis to exist
  • super() can't be used in an bound ES constructor function() =>
  • super can't be called from an external constructor
  • super can't be called more than once in a constructor
  • super can be called in overridden methods, the syntax becomessuper.methodName()

This leads to some definite breaks in how the original CS classes operated, but probably the biggest restriction is the first one:super() needs to be called in a constructor forthis to exist. The reason this becomes an issue is a pretty common use case:@ parameters.

For example the following code won't compile:

classAclassBextendsAconstructor: (@name)->

This is because to refer to@name we actually have to make asuper() call. connec played with the idea of automatically inserting a super() in the generated code, which required hoisting it to the top of the method. This unfortunately means that a parent constructor is getting called without your knowledge, leading to unpredictable inheritance. You might not want to call the original constructor, but by using@ parameters you inadvertently call into the parent, potentially without fulfilling it's signature requirements.

In addition, the following leads to a race condition:

classAconstructor(@name)classBextendsAconstructor: (@name)->super(@name)

since the@name parameter requires this within the super call.

I understand that sneaking asuper() into the constructor transparently can be an issue, but is there a way to makethis available in a subclass without super? Perhaps a blend of the original CS and ES6?

I personally would want to keep as much of the existing CS syntax as possible.

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp