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

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.

主站蜘蛛池模板: 广平县| 周宁县| 太原市| 徐水县| 南宁市| 安溪县| 凭祥市| 海阳市| 华蓥市| 浙江省| 大城县| 昆明市| 许昌县| 乌拉特前旗| 城步| 泌阳县| 鸡泽县| 新巴尔虎左旗| 宁乡县| 尼玛县| 玉龙| 墨玉县| 卢龙县| 江山市| 西峡县| 嘉兴市| 云霄县| 新建县| 社会| 辽中县| 大同县| 西贡区| 西青区| 电白县| 乌兰浩特市| 乌拉特中旗| 明光市| 博客| 马山县| 南京市| 吉木乃县|