---
title: "Comment by Carlonn Rivers on \"Understanding how to work with the publish/subscribe model in JavaScript\" | Hashnode"
description: "You make it look soooo simple, I&#39;d have cultivated something complex! And it looks really similar to equivalent things such as addEventListener, or on, off,"
url: "https://hashnode.com/posts/understanding-how-to-work-with-the-publishsubscribe-model-in-javascript/62b7ca6cb86f939ac81b6a4f/comment/62bdb445e4246414d3d2d4bb"
---

[Discussion](https://hashnode.com/posts/understanding-how-to-work-with-the-publishsubscribe-model-in-javascript/62b7ca6cb86f939ac81b6a4f)

Comment [Understanding how to work with the publish/subscribe model in JavaScript](https://hashnode.com/posts/understanding-how-to-work-with-the-publishsubscribe-model-in-javascript/62b7ca6cb86f939ac81b6a4f)

[Carlonn Rivers](https://hashnode.com/@Danidre)

[Jun 30, 2022](https://hashnode.com/posts/understanding-how-to-work-with-the-publishsubscribe-model-in-javascript/62b7ca6cb86f939ac81b6a4f/comment/62bdb445e4246414d3d2d4bb)

You make it look soooo simple, I'd have cultivated something complex!

And it looks really similar to equivalent things such as addEventListener, or on, off, and emit!

In this case, how would it be possible to unsubscribe a particular function?

[Hunter Trammell](https://hashnode.com/@trammellwebdev)

[Jun 30, 2022](https://hashnode.com/posts/understanding-how-to-work-with-the-publishsubscribe-model-in-javascript/62b7ca6cb86f939ac81b6a4f/comment/62bdb445e4246414d3d2d4bb#reply-62bdbfc679c4ef14aeaad1da)

Thank you! And yes it is very similar to using an event listener especially if you are creating a custom event listener. As for the unsubscribe, one implementation would be to update our subscribe method to return an unsubscribe function that essentially finds the index of the callback function and removes it from our bus\[event\] array. Since we are using array.push when adding our function we could utilize that to get our index since it returns the index of what was added!
