Loading topic
this works inside a method, and the difference between data properties and accessor properties from the previous chapter. Here you will write accessors directly in an object literal, the shortest way to create them.2 min readthis works inside methods, and the basics of the prototype chain. You have already seen get and set in object literals. Class syntax uses the same keywords. The difference is where the resulting property ends up.2 min readthis works inside methods, and how getters and setters are declared in classes (covered in the previous chapter).2 min read# fields. Here you put the two together. The public accessor checks and cleans the input, and the private field holds the value that passed those checks.2 min read#count behave. The same # prefix also works on methods and on accessors. Private methods let you split a class into small internal helpers. Private accessors let you hide com2 min readextends links classes, and how property descriptors describe accessor properties. Here the same get and set syntax is moved from instances to the class itself.2 min read#field) work and how static getters and setters are declared on a class. It shows how to keep class-level state hidden with the same # syntax.2 min readinstanceof and prototypes work, and the private field syntax covered in the earlier chapter on private fields.2 min readthis keyword, and that you have read the earlier chapter on private fields. Private # fields arrived in ES2022. Before that, developers hid state in three main ways. You will still find all three in existing codebases and libraries,3 min readclass and extends, how super calls work, how the prototype chain resolves property lookups, and the basics of accessor properties and # private fields from earlier chapters. Here we look at what changes when a subclass inherits from a class that uses them2 min read#field in obj brand check, and how accessors behave under extends. Each section below describes one mistake, shows what goes wrong, and gives the usual fix.2 min read