OOP Flashcards

1
Q

What is encapsulation

A

Bundling data and operations related to that data in a cohesive unit called an object

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

What is OOP

A

A programming paradigm where we think of a problem in terms of objects

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

Advantages of OOP

A

Programmers think of program at a higher-level of abstraction, reduce dependencies in a program, easy to understand

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

Disadvantages of OOP

A

Often much larger than procedural programs, less efficient code - memory, computing power

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

How is JS encapsulation different from other languages?

A

JS does not directly limit exposure to methods and properties.

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

A factory function returns

A

an object

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

One object factory can reuse another object factory by:

A

mixing object returned by other factory function into itself using object.assign

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

forEach loops vs for loops

A

forEach loops over only ‘own’ properties. for loops over all the enumerable properties

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

How do you create an object that doesn’t have a prototype?

A

Object.create(null)

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

method to get prototype of an object

A

Object.getPrototypeOf(obj)

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

What does enumerable mean?

A

The property will show up if you iterate over the object using a for loop or Object.keys

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

What is an interface of an object?

A

The state and behaviors exposed by the object for other objects to use.

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

What can you use as the value of a property in an object?

A

string, float, null, function object, another object. Any valid JS value

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

What is a collaborator object and 2 examples.

A

They represent the connections between various actors in your program. A primitive value and an object that is part of the state of another object

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

A benefit of collaborator objects

A

They let you chop up and modularize the problem domain into cohesive pieces.

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

Use Object.create to

A

create a new object, using an existing object as the prototype of the newly created object

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

Use Object.setPrototypeOf to

A

set the prototype of an object that already exists

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

By default, all object literals inherit from

A

Object.prototype

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

What built-in methods have we learned about that we can use to specify a function’s execution context explicitly?

A

call and apply

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

bind returns

A

a new function permanently bound to first argument

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

Global execution context is created when?

A

before any code is executed

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

A new execution context gets created when

A

whenever a function is executed

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

A downstream object can override a property if

A

it has a property with the same name

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

Function invocations - execution context?

A

rely upon implicit execution context that resolves to the global object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Method invocations - execution context?
implicit execution context - resolves to object connected to method
26
The value of this is
The current execution context of a function or method
27
Arrow functions are permanently bound to
the execution context of the enclosing function invocation (usually global object)
28
Javascript has 1st class functions that can do these 3 things:
1) Add them to objects and execute them in that object 2) Remove them from their objects, pass around, and execute in other contexts 3) Dynamically bound to a context at execution time
29
child object delegates invocation of a method call to parent object or other way around
child object delegates to parent object!
30
Object.getPrototypeOf({}) returns
A reference to the default prototype object
31
for loop will go through even the properties and methods that
aren't directly set in the new object
32
Do all objects in JavaScript have an object prototype?
you can use Object.create(null) to create an object that doesn't have a prototype
33
Can you hoist with a function declaration or a function expression
function declaration (where the word function comes first on the line)
34
JavaScript runs programs in two passes;
the first pass performs hoisting, and the second executes the code.
35
All JavaScript functions are
first-class entities.
36
All arrow functions in JavaScript are
anonymous functions.
37
How many functions can you pass to another function
as many as you want
38
Any function can return
another function
39
Higher-order functions are also
first-class values.
40
A function that returns a function is
a higher-order function.
41
A function that accepts one or more arguments that are themselves functions is
a higher-order function.
42
When does JavaScript bind an object to this
When the function is executed using method-call syntax, e.g., foo.bar(). When the function is executed by either apply or call. When the function is executed using function-call syntax, e.g., bar()
43
What naming convention separates constructor functions from other functions?
Constructor function names are capitalized.
44
What is the static modifier?
A static method is defined directly on the class, not on the objects the class creates.
45
All objects that have a length property are
array-like objects
46
If A is a class, what does typeof A return
typeof A returns "function"
47
JS is a what type of OO language?
Prototypal OO language. Meaning objects can inherit directly from other objects
48
Pseudoclassical Inheritance uses
A constructor function and the 'new' operator to create objects and the 'prototype' property to build the inheritance chain. Also known as constructor inheritance
49
Prototypal Inheritance is creating _______
a new object from an existing object, using object.create()
50
An instance method or property is from
the object creator - like with the class Person, 'Daniel' would be an instance and we're talking about the methods and properties he has
51
In OLOO objects inherit _
directly from other objects without constructor - subset of prototypal inheritance
52
What is polymorphism
Polymorphism is the ability of an object to take on many forms. Objects share behaviors and override shared behaviors with specific ones. It uses inheritance to do this.
53
Constructor function uses
this.argument (which can be property or method - methods are properties) and the new keyword
54
Factory function returns
an object, just return and then argument separated by commas
55
Built-in constructors examples are
Array, Object, String, Number
56
The keyword new determines:
whether or not a function is a constructor
57
What are collaborator objects - 2 points
``` First, collaborator objects can be of any type: custom class object, Array, Hash, String, Integer, etc Second, a collaborator object is part of another object’s state. ```
58
How is multiple inheritance done
with mix-ins
59
A mixin is a _______
Object (defined by const) containing methods that can be used by other classes
60
Mixins vs inheritance
mix-in is a restricted case of multiple inheritance
61
method invocation vs. function invocation
method invocation 'this' binds to the current object and when you call function invocation pattern 'this' binds to global object
62
A higher order function is
a function that takes a function as an argument, or returns a function
63
Global object is:
A global object is an object that always exists in the global scope
64
execution context is
a concept that holds information about the environment within which the current code is being executed
65
For every function call,
the JavaScript engine creates a new Function Execution Context. It creates the arguments object that contains a reference to all the parameters passed into the function
66
bind is a property of
functions
67
Implicit binding (functions) - what do you do?
Look to the left of the dot
68
Explicit binding
Call, apply, or bind
69
Context loss usually happens in
nested functions