Object-oriented Programming in JS Flashcards
What are the 4 pillars of OOP
Encapsulation
Abstraction
Polymorphism
Inheritance
what is Encapsulation?
group related variable and functions together and reuse
What is Abstraction?
hide details and complexity and only show essentials
What is Inheritance?
eliminate redundant code
What is Polymorphism?
allows code to change
what is a function in an object called?
method.
the constructor property that references ______
the function that was used to create the object
let x = 10
function increase(x){ x++; } increase(x); console.log(x);//
10
let obj = {value: 10}
function increase(obj){ obj.value++; } increase(obj); console.log(obj.value);//
11
The method to get the keys of an object
Object.keys(object);
function Circle (radius, color){ this.radius = radius // this.color = color; }
HIDE COLOR FROM THE OUTSIDE
// let color = color;
What is temporal: SCOPE or CLOSURE?
scope
A getter is a ___?
a function that is used to read a property
Make the following falsy
if (value.x || value.y){ // code }
(!value.x || !value.y){
Another simple explanation for prototype explanation. A prototype is a __________
parent
Every object (except the root object) has a prototype (parent). To get the prototype of an object: //
Object.getPrototypeOf(obj);
Every object in Javascript has a prototype or parent except the _________
root object.
Objects created by a given constructor will have the same _______
prototype
________ created by a given constructor will have the same prototype
Objects
let person = {name: "steve'}; get prototype or person
object.getPrototypeOf(person);
to make an element of an object read only:
writeable: FALSE
The static method ____________ defines a new property directly on an object, or modifies an existing property on an object, and returns the object.
Object.defineProperty()
to make an element of an object not show up in object.key :
enumerable: FALSE
to ensure you can not delete a property of an object:
configureable: FALSE
6 element of
Object.defineProperty()
Get Set Writable Configurable Enumerable Value
To get the attributes of a property in an object use the method ______ ?
Object.getOwnPropertyDescriptor()
What uses a return statement,
GET or SET?
GET
Make an object property read only
writable: false
// To get the own/instance properties:
Object.keys(obj);
// To get all the properties (own + prototype):
for (let key in obj) {}
const x = {}; const y = {}; Object.getPrototypeOf(x) === Object.getPrototypeOf(y); //
returns true
Object.prototype === Object.getPrototypeOf({})
TRUE
Array.prototype === Object.getPrototypeOf([])
TRUE
proper way to get a prototype of an object is buy using )))
Object.getPrototypeOf( )
the object method ____ is the same as __proto___
Object.getPrototypeOf()
object.prototype is equal too _____
obj.__proto__
The 2 types of members of objects
- instance members
2. prototype members
What will return (instance + prototype) in a objects:
for(let key in obj) console.log(key);
object.keys(obj)
for in loop returns (instance + prototype)
______ expresses a lack of identification, indicating that a variable points to no object.
Null
The only way to create a new JavaScript Date object is to use the _____ operator:
new
make a new date
let x = new date ();
const seconds = (endTime.getTime() -startTime.getTime()); returned 13160
FIX code above to get 13.160
(endTime.getTime() -startTime.getTime() / 1000);
every object has a constructor property that
returns the function that was used to construct the object