In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to use js to achieve custom events", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to implement custom events with js".
1. Specify who is the publisher
2. Add a cache list to the publisher to store the callback to notify the subscriber.
3. When the message is published, the publisher will traverse the list and in turn trigger the subscriber callback function stored in it.
Example
Const salesOffices = {} / / define sales office salesOffices.clientList = [] / / cache list, store subscriber callback function salesOffices.listen = function (fn) {/ / add subscriber this.clientList.push (fn) / / add to cache list} salesOffices.trigger = function () {/ / publish message for (let I = 0, fn; fn = this.clientList [iTunes +] ) {fn.apply (this, arguments) / / arguments is the parameter}} / / Test salesOffices.listen ((price, squareMeter) = > {/ / Xiaoming subscription message console.log ('price =' + price) console.log ('squareMeter=' + squareMeter)}) salesOffices.listen ((price)) SquareMeter) = > {/ / Xiao Hong subscription message console.log ('price =' + price) console.log ('squareMeter=' + squareMeter)}) salesOffices.trigger (2000000, 88) salesOffices.trigger (3000000, 110) so far I believe you have a deeper understanding of "how to use js to achieve custom events". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.