OOP Flashcards
What is encapsulation
Bundling data and operations related to that data in a cohesive unit called an object
What is OOP
A programming paradigm where we think of a problem in terms of objects
Advantages of OOP
Programmers think of program at a higher-level of abstraction, reduce dependencies in a program, easy to understand
Disadvantages of OOP
Often much larger than procedural programs, less efficient code - memory, computing power
How is JS encapsulation different from other languages?
JS does not directly limit exposure to methods and properties.
A factory function returns
an object
One object factory can reuse another object factory by:
mixing object returned by other factory function into itself using object.assign
forEach loops vs for loops
forEach loops over only ‘own’ properties. for loops over all the enumerable properties
How do you create an object that doesn’t have a prototype?
Object.create(null)
method to get prototype of an object
Object.getPrototypeOf(obj)
What does enumerable mean?
The property will show up if you iterate over the object using a for loop or Object.keys
What is an interface of an object?
The state and behaviors exposed by the object for other objects to use.
What can you use as the value of a property in an object?
string, float, null, function object, another object. Any valid JS value
What is a collaborator object and 2 examples.
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
A benefit of collaborator objects
They let you chop up and modularize the problem domain into cohesive pieces.
Use Object.create to
create a new object, using an existing object as the prototype of the newly created object
Use Object.setPrototypeOf to
set the prototype of an object that already exists
By default, all object literals inherit from
Object.prototype
What built-in methods have we learned about that we can use to specify a function’s execution context explicitly?
call and apply
bind returns
a new function permanently bound to first argument
Global execution context is created when?
before any code is executed
A new execution context gets created when
whenever a function is executed
A downstream object can override a property if
it has a property with the same name
Function invocations - execution context?
rely upon implicit execution context that resolves to the global object
Method invocations - execution context?
implicit execution context - resolves to object connected to method
The value of this is
The current execution context of a function or method
Arrow functions are permanently bound to
the execution context of the enclosing function invocation (usually global object)