JavaScript · Senior · Question 17 of 75

How do you implement the observer pattern with browser APIs, without libraries?

Explanation

You can extend a class from EventTarget and dispatch new CustomEvent('change', { detail }). Other built-in observers: MutationObserver (DOM changes), IntersectionObserver, ResizeObserver. Object.observe was removed from the standard.

Further reading

Problem with a question

JavaScript · Senior · question 17

Test yourself

Take the JavaScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz