I want to know what the js function stopObserving()
is used for.
1 Answer
Say you have a form input where you are observing the keyUp
event. If you wanted to no longer listen to this event, maybe because the value passes validation or is no longer required to validate due to other form values, you would call stopObserving
on that elements keyUp
observer to no longer listen to this event.
The main reason is to help keep the footprint of the JavaScript small. Especially if you have lots of dynamic elements and are doing lots through JavaScript. Not listening for an event can help save fractions of time and keep your site feeling snappy and responsive to inputs.