Aspect-Oriented Programming in JavaScript

Now that you’ve seen what it is and what it does, you’ve probably guessed why people would want to use Aspect-Oriented Programming, but let’s quickly do a round-up:

  • Great way to encapsulate cross-cutting concerns. I’m a big fan of encapsulation because it means you get easier to read and easier to maintain code that can be re-used all across your project.
  • Flexible logic. The logic around your implementation of the advice and pointcuts can give you a lot of flexibility when it comes to injecting your aspects. This in turn can help to dynamically turn on and off different aspects (pun definitely intended) of your logic.
  • Re-use aspects across projects. You can think of aspects as components, small and decoupled pieces of code that can run anywhere. If you write your aspects correctly, you can share them across different projects with ease.

Because not everything is perfect, some detractors speak against this paradigm.

Their main problem with it is that its main benefit is actually hiding logic and complexity, potentially causing side effects without being too clear about it.

And if you think about it, they’re kind of right, AOP gives you a lot of power to add unrelated behavior into existing methods or even replace their entire logic. Of course, that might not be exactly why this pattern was introduced, and it’s certainly not the intention of the example I provided above.

However, it does provide you with the ability to do whatever you want, and that, coupled with a lack of understanding of good programming practices, can cause a really big mess.

And without trying to sound too cliched here, paraphrasing Uncle Ben:

With big power, comes great responsibility

And with AOP comes the obligation to understand software development best practices if you want to use it correctly.

But if you ask me, just because with this tool you can cause a lot of harm, it doesn’t mean it’s bad, because you can also cause a lot of good (i.e you can extract a lot of common logic into a centralized location and inject it wherever you need, with a single line of code). That to me is a powerful tool worth learning about and definitely, worth using.

Author: Shantun Parmar

26 thoughts on “Aspect-Oriented Programming in JavaScript

  1. Thanks for visiting,
    I’m Mikaeel Rigby.
    If you’ve ever been too tired and couldn’t finish a academic paper, then you’ve come to the right place. I assist students in all areas of the writing steps . I can also write the assignment from start to finish.
    My career as an academic writer started early in college . After learning that I was very talented in the field of academic writing, I decided to take it up as a profession.

    Talented Academic Writer- Mikaeel- twistedspinster.comConfederation

  2. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  3. Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

  4. Thanks on your marvelous posting! I genuinely enjoyed reading it, you are a great author.I will make certain to bookmark your blog and will eventually
    come back later on. I want to encourage you to ultimately continue your great writing, have
    a nice day!

  5. As I site possessor I believe the content material here is rattling great , appreciate it for your efforts. Jennica Dmitri Blessington

Thanks for your support, You may click on ads to encourage us which assits to writers.

Leave a Reply

Your email address will not be published.