Classes Flashcards
Get a job
What are classes?
A template for creating objects. They encapsulate data with code to work on that data.
Classes in JavaScript are built on prototypes but also have syntax and semantics that are unique to classes.
What are getters?
A method that retrieves the value of a property. To define a getter, the method name must be preceded by the “get” keyword. Also, getters are accessed without parentheses, as if they were properties.
Getters can perform computations or transformations before returning a value.
What constitutes the body of a class?
Everything enclosed by the curly braces, that’s where class memebers are defined (methods, contructor, etc).
The body of a class is executed in strict mode even without the “use strict” directive.
A class element can be characterized by three aspects:
Kind: getter, setter, method or field.
Location: static or instance.
Visibility: public or private.
What is a contructor?
A special method for creating and initizalizing an object created with a class. There can only be one special method with the name “constructor” in a class.
A constructor can use the “super” keyword to call the constructor of the super class.
You can create properties inside the constructor.
What is a setter?
A method defined with the “set” keyword. Binds an object property to a function to be called when there is an attempt to set that property.
What are instance variables?
An object is an instance of the class that is created from. Instance variable are all of the properties defined in the class for that object (typically inside the constructor). Every instance variable is accesible using “this.” prefix inside any the instance methods.
What are private fields?
Properties that cannot be accessed from outside the class. They’re created using a “#”.
What is inheritance?
Inheritance refers to passing down characteristics from a parent to a child so that a new piece of code can reuse and build upon the features of an existing one.
What are static methods?
Methods that belong to the class itself. They don’t have access to the “this” object.
What is super?
A keyword used to access properties on an object literal or class’s [[Prototype]], or invoke a superclass’s constructor.