Chapter 9: Classes Flashcards
(12 cards)
two objects are instances of the same class if and only if they
inherit from the same ______ object
prototype
If we have an object r and want to
know if it is a Range object, we can write
r instanceof Range // => true: r inherits from
The _____ is declared with the class keyword, which is
followed by the name of class and a class body in curly braces
class
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
constructor
If you want to define a class that subclasses—or inherits from—
another class, you can use the ______ keyword with the class
keyword
extends
You can define a static method within a class body by prefixing the
method declaration with the _____ keyword
static
You’ll sometimes see static methods called ____ ______ because they
are invoked using the name of the class/constructor
class methods
Here, for example, is code that adds a method for computing the
complex conjugate to the Complex class
// Return a complex number that is the complex conjugate of
this one.
Complex.prototype.conj = function() { return new
Complex(this.r, -this.i); };
In order to make Span a subclass of Range, we need to arrange for
________ to inherit from ________
Span.prototype, Range.prototype
In ES6 and later, you can create a superclass simply by adding an
______ clause to a class declaration
extends
If you define a class with the _____ keyword, then the
constructor for your class must use ______ to invoke the
superclass constructor
extends(), super()
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
this