Javascript Object Oriented Programming Flashcards
What 4 things happen when the NEW keyword gets called with a function call?
- A brand new OBJECT gets created
- An OBJECT gets linked
- The context gets set to the THIS
- returns THIS
What are characteristics of Protypal Inheritance in JavaScript?
- Prototype Chain - behavior is delegated up the prototype chain if it is not available on the new object
- .prototype links the function to an object
- [[Prototype]] internally links one object to another (not public)
- __proto__ (dunder proto) “public property” a getter function which returns the prototypal linkage of THIS
What is a CONSTRUCTOR?
A function called with the NEW keyword in front of it
What is the execution context in JavaScript?
How Javascript code is executed depending on when and where functions and variables are called
What is the Execution Context Stack?
- in Javascript it is single threaded
- Synchronous execution
- 1 global context
- Can have many function contexts
- each function call creates a new execution context
How do you access a value in a JS Object that has a number as its property?
You have to use bracket notation
myObject[3]
What is a Reference Data Type?
Stores the value of that data as a reference. You can change the value of that reference
ex: var person = "Kobe"; var anotherPerson = person;
What are the 3 Attributes of Object Data Properties?
- Configurable - tells if you can delete or change
- Enumerable - can be returned in a for/in loop
- Writable - property can be changed
How do you SERIALIZE an object?
You convert it to a string. You can use JSON.stringify( )
Explain how the concept of THIS works in JavaScript?
- used for dynamic scoping
1. Explicit Binding - call and apply explicitly binds THIS to the first argument you pass in
2. Default Binding - global scope
What is Object Oriented Programming?
Object Oriented Programming is a paradigm in computer science or ‘style’ of programming where objects are instantiated via classes and can contain methods that are inherited by new class objects.
What are the 4 basic concepts of OOP?
Abstraction.
Encapsulation.
Inheritance.
Polymorphism.
What is a class?
A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object.
What is an object?
Object is termed as an instance of a class, and it has its own state, behavior and identity.
What is Encapsulation?
Encapsulation limits prototype methods to the class object
Encapsulation is an attribute of an object, and it contains all data which is hidden. That hidden data can be restricted to the members of that class.
What is Polymorphism?
assigning behavior or value in a subclass to something that was already declared in the main class.
What is Inheritance?
Inheritance is a concept where one class shares the structure and behavior defined in another class. If inheritance applied on one class is called Single Inheritance, and if it depends on multiple classes, then it is called multiple Inheritance.
What are manipulators?
Manipulators are the functions which can be used in conjunction with the insertion (<>) operators on an object. Examples are endl and setw.
What is a constructor?
Constructor is a method used to initialize the state of an object, and it gets invoked at the time of object creation.
What is a destructor?
Destructor is a method which is automatically called when the object is destroyed.
What is an Inline function?
Inline function is a technique used by the compilers and instructs to insert complete body of the function wherever that function is used in the program source code.
What is a virtual function?
Virtual function is a member function ofclass and its functionality can be overridden in its derived class. This function can be implemented by using a keyword called virtual, and it can be given during function declaration.
Virtual function can be achieved in C++, and it can be achieved in C Languageby using function pointers or pointers to function.
What is a friend function?
Friend function is a friend of a class that is allowed to access to Public, private or protected data in that same class. If the function is defined outside the class cannot access such information.
Friend can be declared anywhere in the class declaration, and it cannot be affected by access control keywords like private, public or protected.
What is function overloading?
Function overloading is defined as a normal function, but it has the ability to perform different tasks. It allows creation of several methods with the same name which differ from each other by type of input and output of the function.
Example void add(int& a, int& b); void add(double& a, double& b); void add(struct bob& a, struct bob& b);