Objects Flashcards
JS objects are simple collections of named … with ….
JavaScript objects are simple collections of named properties with values
JavaScript inheritance uses ….
Prototypes and a prototype chain, known as prototypal inheritance
Every object can have a reference to a … but it differs from the … on a …
Prototype, prototype property, function
We can define the prototype of an object by using the … method
Object.setPrototypeOf()
Every function has a …. property
Prototype property, not to be confused with the __proto__ / [[Prototype]] link on an object.
A function’s prototype property has a … property pointing back to itself
constructor
What is returned from the Person function?
function Person() {}
const x = new Person();
An object - an instance of the Person ‘class’.
The ES6 class syntax is really what under the hood?
Syntactic sugar for the constructor function / new keyword technique for prototypal inheritance
What does the super() call do?
It calls the parent class’s constructor function
Which of the following properties points to an object that will be searched if the target object doesn’t have the searched-for property?
- a class
- b instance
- c prototype
- d pointTo
c) prototype
After running the following code, what will ninja.constructor point to?
function Person() {}
function Ninja() {}
Ninja.prototype = new Person();
const ninja = new Ninja();
ninja.constructor will point to Person()
The Object.setPrototypeOf() method sets the … of a specified object to … or …
The Object.setPrototypeOf() method sets the prototype (i.e., the internal [[Prototype]] property) of a specified object to another object or null.
What are the parameters a & b in the following example?
Object.setPrototypeOf(a, b)
a: target object - the object which is to have its prototype set
b: prototype object - the object’s new prototype (an object or null)
What is the return value of Object.setPrototypeOf()?
The specified object that has its prototype changed
What is printed to the console?
const a = { speed: 100 };
const x = Object.setPrototypeOf({}, a);
console.log(x.speed);
100