Yangshun Interview Questions Flashcards

1
Q

Explain Event Delegation

A

This is a technique used to add event listeners to a parent element instead of the descendant elements. The listener will fire whenever the event is triggered on the descendant elements due to the even bubbling up the DOM. Benefits are:

  • Memory footprint goes down because only one single handler is needed on the parent element, rather than having to attach event handlers on each descendant.
  • There is no need to unbind the handler from elements that are removed and to bind the event for new elements.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does prototypal inheritance work?

A

All JavaScript objects have a prototype property, that is a reference to another object. When a property is accessed on an object and if the property is not found on that object, the JavaScript engine looks at the object’s prototype, and the prototype’s prototype and so on, until it finds the property defined on one of the prototypes or until it reaches the end of the prototype chain. This behavior simulates classical inheritance, but it is really more of delegation than inheritance.

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