Ad. Javascript.info part 1 Flashcards
Advanced working with functions - Recursion and stack - Rest parameters and spread operator
An object is a ________________.
collection of properties and has a single prototype object.
The prototype of an object may be ______ or ______
either an object or the null value
A prototype of an object is referenced by the hidden internal _________ and property
[[Prototype]]
A finite chain of objects which is used to implement inheritance and shared properties
Prototype chain
code reuse stylistics is called the
class-based inheritance
is the actual object that is used in the lookup chain to resolve methods, etc.
__proto__ or [[prototype]]
is the object that is used to build __proto__ when you create an object with new:
prototype
If the property is not found after the whole prototype chain lookup, then ________ is returned.
undefined value
Object.prototype itself also has a __proto__, which is the final link of a chain and is set to______.
null
a constructor function does another useful thing — it automatically sets a ___________ for newly created objects.
prototype object
function Foo(y) { this.y = y; }
// inherited property "x" using constructor \_\_\_\_\_\_\_\_\_\_\_\_\_\_= 10;
Foo.prototype.x
every object has a prototype
TRUE / FALSE
TRUE
An object specifies its prototype via the internal property_________
[[Prototype]]
What constitute a prototype chain are the __proto__ pointing up the chain, and the objects pointed to by __proto__, such as going from foo.__proto__, going up to foo.__proto__.__proto__, and so forth, until _______
null is reached.
By default, JavaScript engine provides the Object() funtion and an anonymous object that can be referenced to via the ________
Object.prototype.
The Object.prototype object has many built-in properties such as toString(), valueOf(), etc. It also has a property named_______ that points back to the _________
constructor
Object() function
console.log(Object.prototype.constructor !== Object); //
false
console.log(Object.prototype.constructor === Object); //
true
let point = {
x: 10,
y: 20,
};
how many properties?
how many __proto__?
2 properties
1 __proto__
Every object, when is created, receives it’s ______
prototype
If the prototype is not set explicitly, objects receive _________as their inheritance object.
default prototype
// Base object. let point = { x: 10, y: 20, };
// Inherit from `point` object. let point3D = { z: 30, \_\_proto\_\_: point, };
inherited or own
console.log( point3D.x, // 10, point3D.y, // 20, point3D.z // 30, );
inherited
inherited
own
a delegation object used to implement prototype-based inheritance.
protoype
finite chain of objects used to implement inheritance and shared properties.
prototype chain
a mechanism used to resolve a property in the inheritance chain. The process happens at runtime, hence is also called dynamic dispatch.
delegation
delegation
a mechanism used to resolve a property in the inheritance chain. The process happens at runtime, hence is also called dynamic dispatch.
another name for delegation
dynamic dispatch.
let empty = {};
console.log(empty.x);
// undefined
To create a prototype-less dictionary, we have to explicitly set its prototype to ______
null
// Doesn't inherit from anything. let dict = \_\_\_\_\_\_\_\_\_\_
Object.create(null);
let dict = Object.create(null);
console.log(dict.toString); //
undefined
let protoA = {x: 10}; let protoB = {x: 20};
CREATE OBJECTC WRITE USING __PROTO__
console.log(objectC.x); // 10
let objectC = {__proto__: protoA};
let protoA = {x: 10}; let protoB = {x: 20};
CREATE OBJECTC WRITE USING .CREATE
console.log(objectC.x); // 10
let objectC = Object.create(protoA);
let protoA = {x: 10}; let protoB = {x: 20};
// Change the delegate to protoB DONT USE __PROTO__
console.log(objectC.x); // 20
Object.setPrototypeOf(objectC, protoB);
When several objects share the same initial state and behavior, they form a________
classification
________ is a formal abstract set which specifies initial state and behavior of its objects.
a class
var a = {}; Object.getPrototypeOf(a); // alert(a.\_\_proto\_\_);
[object Object]
a________ function creates objects, and also automatically sets the prototype for its newly created instances
constructor
Object is an unordered or ordered collection of key-value pairs.
unordered
function A() { this.x = 10; return [1, 2, 3]; }
var a = new A(); console.log(a.x, a);
undefined, [1, 2, 3]
function A() {} var a = new A(); console.log(a.constructor); // console.log(a.constructor === A); //
function A() {}, by delegation
true