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
Q

Method invocations - execution context?

A

implicit execution context - resolves to object connected to method

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

The value of this is

A

The current execution context of a function or method

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

Arrow functions are permanently bound to

A

the execution context of the enclosing function invocation (usually global object)

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

Javascript has 1st class functions that can do these 3 things:

A

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
Q

child object delegates invocation of a method call to parent object or other way around

A

child object delegates to parent object!

30
Q

Object.getPrototypeOf({}) returns

A

A reference to the default prototype object

31
Q

for loop will go through even the properties and methods that

A

aren’t directly set in the new object

32
Q

Do all objects in JavaScript have an object prototype?

A

you can use Object.create(null) to create an object that doesn’t have a prototype

33
Q

Can you hoist with a function declaration or a function expression

A

function declaration (where the word function comes first on the line)

34
Q

JavaScript runs programs in two passes;

A

the first pass performs hoisting, and the second executes the code.

35
Q

All JavaScript functions are

A

first-class entities.

36
Q

All arrow functions in JavaScript are

A

anonymous functions.

37
Q

How many functions can you pass to another function

A

as many as you want

38
Q

Any function can return

A

another function

39
Q

Higher-order functions are also

A

first-class values.

40
Q

A function that returns a function is

A

a higher-order function.

41
Q

A function that accepts one or more arguments that are themselves functions is

A

a higher-order function.

42
Q

When does JavaScript bind an object to this

A

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
Q

What naming convention separates constructor functions from other functions?

A

Constructor function names are capitalized.

44
Q

What is the static modifier?

A

A static method is defined directly on the class, not on the objects the class creates.

45
Q

All objects that have a length property are

A

array-like objects

46
Q

If A is a class, what does typeof A return

A

typeof A returns “function”

47
Q

JS is a what type of OO language?

A

Prototypal OO language. Meaning objects can inherit directly from other objects

48
Q

Pseudoclassical Inheritance uses

A

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
Q

Prototypal Inheritance is creating _______

A

a new object from an existing object, using object.create()

50
Q

An instance method or property is from

A

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
Q

In OLOO objects inherit _

A

directly from other objects without constructor - subset of prototypal inheritance

52
Q

What is polymorphism

A

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
Q

Constructor function uses

A

this.argument (which can be property or method - methods are properties)
and the new keyword

54
Q

Factory function returns

A

an object, just return and then argument separated by commas

55
Q

Built-in constructors examples are

A

Array, Object, String, Number

56
Q

The keyword new determines:

A

whether or not a function is a constructor

57
Q

What are collaborator objects - 2 points

A
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
Q

How is multiple inheritance done

A

with mix-ins

59
Q

A mixin is a _______

A

Object (defined by const) containing methods that can be used by other classes

60
Q

Mixins vs inheritance

A

mix-in is a restricted case of multiple inheritance

61
Q

method invocation vs. function invocation

A

method invocation ‘this’ binds to the current object and when you call function invocation pattern ‘this’ binds to global object

62
Q

A higher order function is

A

a function that takes a function as an argument, or returns a function

63
Q

Global object is:

A

A global object is an object that always exists in the global scope

64
Q

execution context is

A

a concept that holds information about the environment within which the current code is being executed

65
Q

For every function call,

A

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
Q

bind is a property of

A

functions

67
Q

Implicit binding (functions) - what do you do?

A

Look to the left of the dot

68
Q

Explicit binding

A

Call, apply, or bind

69
Q

Context loss usually happens in

A

nested functions