Kyle creates one more custom event to initialize all modules. This way the application does not need to know what modules are currently loaded. Kyle also demonstrates the power of custom events by adding an additional link that can load details.
(oriental music)…- That's not the only place that we can use events.…What about our init function?…We're manually calling that init function…from inside of our app.…What if we took window.event,…I actually didn't even need to put that in the jQuery thing.…This is not related to the DOM at all.…What if we took this code that's inside of document.ready…and instead of calling header.init…and carousel.init and whatever,…what if we just published an event…that people could listen to?…Like, for example, EVT.emit(init),…that's a good event name.…
Now I have absolutely no idea…what other modules are on the page.…I don't care if they're there or not.…I'm just going to throw out the event.…And inside of each one of my modules,…instead of it needing,…I don't even need this method to be on a public API anymore.…I can leave it there just for simplicity,…but it's not even needed anymore.…Inside of this code, not inside of my init,…but inside of my module instantiation,…I just need to listen for the init event.…EVT.on("init"), and what function do I call?…
Note: This course was created on 03/29/2016 by Frontend Masters. We are pleased to host this content in our library.
- Carousels, panes, and modules
- Middle-end architecture
- Secure phrase generator
- Routing functions
- Calling the API
- Rendering on the page
- Shared data validation
Skill Level Intermediate
2. Organizing Code
5. Adding a Shared Module
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.