官术网_书友最值得收藏!

Summary

In this chapter, we learned about the Observer Pattern, how it can make the HTML code of our web pages cleaner, and the way that decouples it from our application's code. We learned how jQuery adds a protection layer to its methods in order to protect us from undetected memory leaks, which may occur by adding observers to elements, when not using the jQuery DOM manipulation methods.

We also tried the Delegated Event Observer Pattern variant and used it to rewrite our initial example. We compared the two implementations and saw how it simplifies writing code that applies to many page elements when they are generated after the page has been loaded. Finally, we had a comparison regarding the memory consumption of the plain Observer Pattern with its delegate variant and highlighted how it also lessens the memory consumption of our page by reducing the required number of attached observers.

Now that we have completed our introduction on how the Observer Pattern is used to listen to user actions, we can move on to the next chapter where we will learn about custom events and the Publish/Subscribe Pattern and the way they can lead to a more decoupled implementation.

主站蜘蛛池模板: 宝兴县| 光山县| 武威市| 宁晋县| 黄冈市| 唐海县| 通海县| 吴旗县| 伽师县| 榕江县| 汉源县| 石柱| 腾冲县| 新津县| 江城| 河池市| 龙州县| 盘山县| 临沂市| 绥德县| 繁昌县| 武乡县| 周口市| 保亭| 华坪县| 庆安县| 东平县| 南涧| 辰溪县| 江永县| 霍山县| 吉安市| 曲水县| 南丹县| 乌拉特后旗| 马边| 海宁市| 湘潭县| 井冈山市| 新宁县| 巴青县|