Chapter 9: Classes Flashcards

(12 cards)

1
Q

two objects are instances of the same class if and only if they
inherit from the same ______ object

A

prototype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If we have an object r and want to
know if it is a Range object, we can write

A

r instanceof Range // => true: r inherits from

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

The _____ is declared with the class keyword, which is
followed by the name of class and a class body in curly braces

A

class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The keyword _______ is used to define the constructor
function for the class. The function defined is not actually
named “constructor”, however. The class declaration
statement defines a new variable Range and assigns the value
of this special constructor function to that variable

A

constructor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

If you want to define a class that subclasses—or inherits from—
another class, you can use the ______ keyword with the class
keyword

A

extends

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

You can define a static method within a class body by prefixing the
method declaration with the _____ keyword

A

static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

You’ll sometimes see static methods called ____ ______ because they
are invoked using the name of the class/constructor

A

class methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Here, for example, is code that adds a method for computing the
complex conjugate to the Complex class

A

// Return a complex number that is the complex conjugate of
this one.
Complex.prototype.conj = function() { return new
Complex(this.r, -this.i); };

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In order to make Span a subclass of Range, we need to arrange for
________ to inherit from ________

A

Span.prototype, Range.prototype

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In ES6 and later, you can create a superclass simply by adding an
______ clause to a class declaration

A

extends

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

If you define a class with the _____ keyword, then the
constructor for your class must use ______ to invoke the
superclass constructor

A

extends(), super()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

You may not use the ____ keyword in your constructor until
after you have invoked the superclass constructor with
super(). This enforces a rule that superclasses get to
initialize themselves before subclasses do

A

this

How well did you know this?
1
Not at all
2
3
4
5
Perfectly