Class Flashcards
commas are needed between class methods
TRUE / FALSE
FALSE
class User { constructor(name) { this.name = name; } sayHi() { alert(this.name); } }
alert(typeof User); //
function
class User { constructor() {} }
alert(typeof User);
User(); // returns
Error: Class constructor User cannot be invoked without ‘new’
A class definition sets enumerable flag to ________ for all methods in the “prototype”.
false
Class methods are non-enumerable.
True / False
true
All code inside the class construct is automatically in strict mode.
True / False
True
let User = class MyClass { sayHi() { alert(MyClass); // MyClass is visible only inside the class } };
new User().sayHi(); //
works, shows MyClass definition
let User = class MyClass { sayHi() { alert(MyClass); // MyClass is visible only inside the class } };
alert(MyClass); //
error, MyClass not visible outside of the class
MyClass is technically a ___________ (the one that we provide as constructor), while methods, getters and settors are written to MyClass.prototype.
function
The _________ keyword is used in class declarations or class expressions to create a class which is a child of another class.
extends
The________ keyword is used to access and call functions on an object’s parent.
super
to call a parent method using super
super.methons(…)
to call a parent constructor (inside our constructor only) using super
super(…)
class Animal {
constructor(name) {
this.speed = 0;
this.name = name;
}
run(speed) {
this.speed += speed;
alert(${this.name} runs with speed ${this.speed}.
);
}
stop() {
this.speed = 0;
alert(${this.name} stopped.
);
}
}
class Rabbit extends Animal { hide() { alert(`${this.name} hides!`); }
stop() { \_\_\_\_\_\_\_\_ // call parent stop \_\_\_\_\_\_\_\_\_ // and then hide } }
super. stop();
super. stop();
Arrow functions have super
TRUE / FALSE
Arrow functions have no super