Skip to content
Onsite

Output: class field arrow method vs prototype method, each extracted and called standalone

MediumP2Output

What does this code print?

1class Button {
2 label = 'ok';
3 arrow = () => this.label;
4 proto() {
5 return this === undefined ? 'no this' : this.label;
6 }
7}
8const b = new Button();
9const { arrow, proto } = b;
10console.log(arrow());
11console.log(proto());
12console.log(b.proto());
13console.log(Object.hasOwn(b, 'arrow'), Object.hasOwn(b, 'proto'));
Saved automatically

One line per console.log. Arrays as [1, 2, 3], objects as { a: 1 }, an uncaught error as Uncaught TypeError: message (Chrome and Node wording).

Hints

Saved automatically