Advanced javascript concepts Flashcards

1
Q

explain explicit binding, implicit binding and global binding

A

When in the global scope, the value of “this” will be the window/console Object;
Whenever a preceding dot calls a function, the object before the dot is this.
Whenever we use a constructor function, this refers to the specific instance of the object that is created and returned by the constructor function.
Whenever we use JavaScript’s call or apply method, this is explicitly defined.

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

what is a constructor function in javascript?

A

A constructor function is a function that returns an object. It’s an object creator. We use them a lot in JavaScript, and they lend themselves to a paradigm called object-oriented programming. The function ‘whatever’ will create an object for us. When we call the function, we have to use the new keyword.
A constructor function “constructs” objects. You can think of it as a template. The function itself needs to take in an object literal of some sort so that it can map that object literal’s properties to a new object that will be returned once instantiated.

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

what is the prototype?

A

All objects in JavaScript have a prototype property by default. This property is used as an object to attach methods and other properties that can be delegated down to other child functions/objects.

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

what is prototypal inheritance?

A

The prototype is the mechanism by which all JavaScript objects inherit from one another. You can think of the prototype as an object that objects use to hold onto values that can be passed down to other objects. We use it all the time in inheritance. Prototypal Inheritance: A prototype is a working object instance. Objects inherit directly from other objects.

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

what is the prototype chain?

A

When we look for a property of an object, the JavaScript engine will first check the object itself for the existence of the property. If not found, it’ll go to the object’s prototype and check that object. If found, it’ll use that property.

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

what is class inheritance in javascript and how does it differ from prototype inheritance?

A

Class Inheritance: A class is like a blueprint — a description of the object to be created. Classes inherit from classes and create subclass relationships: hierarchical class taxonomies. In JavaScript, class inheritance is implemented on top of prototypal inheritance, but that does not mean that it does the same thing!

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

why does inheritance matter?

A

Inheritance is fundamentally a code reuse mechanism: A way for different kinds of objects to share code. The way that you share code matters because if you get it wrong, it can create a lot of problems, specifically:
Class inheritance creates parent/child object taxonomies as a side-effect.The tight coupling problem (class inheritance is the tightest coupling available in oo design), which leads to the next one…
The fragile base class problem
Inflexible hierarchy problem (eventually, all evolving hierarchies are wrong for new uses)
The duplication by necessity problem (due to inflexible hierarchies, new use cases are often shoe-horned in by duplicating, rather than adapting existing code)
The Gorilla/banana problem (What you wanted was a banana, but what you got was a gorilla holding the banana, and the entire jungle)

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