Prototypes, inheritance, F.prototype Flashcards
javascript.info Advanced working with functions 6.1 6.2
The property _______is internal and hidden, but there are many ways to set it.
[[Prototype]]
________ is a historical getter/setter for [[Prototype]]
__proto__
__proto__ is the same as [[Prototype]]
TRUE / FALSE
__proto__ is not the same as [[Prototype]]
Object.getPrototypeOf & Object.setPrototypeOf
replaced
__proto__ set and get
let animal = { eats: true }; let rabbit = { jumps: true };
rabbit.__proto__ = animal; // (*)
// we can find both properties in rabbit now:
alert( rabbit.eats ); //
alert( rabbit.jumps ); //
true
true
let animal = { eats: true, walk() { alert("Animal walk"); } };
let rabbit = { jumps: true, \_\_proto\_\_: animal };
let longEar = {
earLength: 10,
__proto__: rabbit
};
longEar.walk(); //
alert(longEar.jumps); //
// walk is taken from the prototype chain Animal walk true // (from rabbit)
The value of __proto__ can be either an_____ or ______, other types (like primitives) are ignored.
object
null
The prototype is used for reading and writing properties
TRUE / FALSE
FLASE
The prototype is only used for reading properties
this is not affected by prototypes at all
TRUE / FALSE
true
No matter where the method is found: in an object or its prototype. In a method call, _______ is always the object before the dot.
“this”
The for..in loops over inherited properties.
TRUE / FALSE
true
The prototype is only used for _________ properties.
reading
let animal = { walk() { if (!this.isSleeping) { alert(`I walk`); } }, sleep() { this.isSleeping = true; } };
let rabbit = {
name: “White Rabbit”,
__proto__: animal
};
rabbit.sleep();
alert(animal.isSleeping); //
undefined (no such property in the prototype)
let animal = { eats: true };
let rabbit = { jumps: true, \_\_proto\_\_: animal };
alert(Object.keys(rabbit)); //
jumps
let animal = { eats: true };
let rabbit = { jumps: true, \_\_proto\_\_: animal };
for(let prop in rabbit) alert(prop); //
jumps, then eats