Skip to content

Related to class fields #1979

@vivek1394Git

Description

@vivek1394Git

Hello there,
It is written in class field section(https://javascript.info/class):
"Technically, they are processed after the constructor has done it’s job, and we can use for them complex expressions and function calls:
`class User {
name = prompt("Name, please?", "John");
}

let user = new User();
alert(user.name); // John`
"

I've checked it using this code.
`class User {
name = prompt("Name, please?", "John");
constructor() {
alert("I was here later!");
}
}

let user = new User();
alert(user.name); // John`

And as I had expected "prompt" was called before "alert", because I think "Class fields are processed before constructor."
I've been learning from your awesome tutorials since some days and they are really awesome.
I want to thank you for these awesome articles!!!

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