Object Oriented Programing Flashcards
What is an object made of?
Properties define what makes up an object. Note that similar objects share the same properties, but may have different values for those properties. For example, all cars have wheels, but not all cars have the same number of wheels.
In OOP, what are methods?
They are objecct properties that are functions.
In OOP, what does the “this.” keyword do?
It makes the variable inextricably associated with the object in which it is declared.
In OOP, what is a constructor?
A function that creates an object. It defines properties and behaviors that will belong to the new object.
What are the rules for constructors?
They are defined with a capitalized name to distinguish them from other types of functions.
They use the keyword this to set properties of the object they will create. Inside it, this refers to the new object it will create.
They define properties and behaviors instead of returning a value as other functions might.
Visualise the creation of a new object.
Comment on the “this” keyword.
What happens if you don’t use the “new” keyword while creating an object?
Without the new operator, this inside the constructor would not point to the newly created object, giving unexpected results.
What is this code?
A constructor with parameters that can be set by the user.
What’s an object called in relation to its constructor?
It’s called an instance of its constructor.
In JavaScript, what does the operator “instanceof” do?
“instanceof” allows you to compare an object to a constructor, returning true or false based on whether or not that object was created with the constructor.
In JavaScript, what happens when you use “instanceof” for an object that wasn’t instantiated using a given constructor?
In OOP, what is an “own property”?
The properties that are defined directly upon instantiation of an object. Which means that each object instantiated from a given contructor will have their own copies of these properties.
In JavaScript, what is a prototype?
A way to give a property to all instances of a class/constructor.
What is the difference between “own property” and prototype?
“Own properties” are defined directly on the object instance itself while prototype properties are defined on the prototype.
Visualise code that would separate an object’s “own properties” from its prototype properties by adding them onto separate arrays.
In JavaScript what is the “constructor” property, how could it be used and what should be noted about it’s utility?
What is an efficient way to add multiple prototypes to a class/constructor?
What’s one crucial side effect of manually setting the prototype to a new object?