Skip to content
This repository was archived by the owner on Jan 25, 2022. It is now read-only.
This repository was archived by the owner on Jan 25, 2022. It is now read-only.

Context of "this" in properties definition #62

@syabro

Description

@syabro

I've created a bug here babel/babel#6977 about ambiguous behavior of this in property definition, but looks like it could be not a bug.

Provide an example code here

class A  {
  state = { value: this.value }

  constructor(val) {
    this.value = val
  }
}

console.log('A.state.value', new A('A').state.value)


class BParent  {
  constructor(val) {
    this.value = val
  }
}

class B extends BParent {
  state = {value: this.value}
}

console.log('B.state.value', new B('B').state.value)

will produce

A.state.value undefined
B.state.value B

I can't find anything about context for this in https://tc39.github.io/proposal-class-fields/

Am I missing something? What's the expected behavior? For me using this in class properties must be restricted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions