Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

AOP aspect of JavaScript with Dojo. Fantastic post—concisely explains Aspect Oriented Programming, then shows how Dojo’s dojox.lang.aspect brings AOP to JavaScript, including some really useful built-in aspects for logging, profiling and more. Aspects are like Python decorators on steroids.

Tagged , , , , , , ,

3 comments

  1. Even if you avoid the explicit d.l.aspect stuff, Dojo makes heavy use of AOP internally, notable in the event API. This can make debugging difficult, as it's hard to see who is calling what from where, but you do gain a lot of flexibility.

    It can be very useful to hook your own synthetic event handlers into third-party code, for instance. An example could be intercepting calls to a library's XmlHTTP function to display a "loading" status message as "before" advice, then tear it down with "after" advice on an internal callback, regardless of where that XmlHTTP function gets invoked from.

    This Dojo event manual page shows how to add advice using the event API: http://dojotoolkit.org/book/dojo-book-0-4/part-5-c onnecting-pieces/event-system/after-and-around-adv ice

    phl - 19th May 2008 13:38 - #

  2. Debugging is my biggest beef with Event APIs and AOP. Trying to navigate code written using lots of event calls is a nightmare - IDE's can't help and having had to learn someone's event-driven system once I'm in no hurry to repeat the experience.

    Flexibility at the expense of maintainability - I don't like it.

    Peter Bowyer - 20th May 2008 11:28 - #

  3. @phi: Dojo 0.9 and later moved away from advice as part of the event system by default, with dojo.connect really being just after advice to streamline performance. The work Eugene did adds advice capabilities back through DojoX, Dojo Extensions, and then some, for when you really need the flexibility or before and around advice, etc.

    Dylan Schiemann - 21st May 2008 05:48 - #

Sign in with OpenID

Auto-HTML: Line breaks are preserved; URLs will be converted in to links.

Manual XHTML: Enter your own, valid XHTML. Allowed tags are a, p, blockquote, ul, ol, li, dl, dt, dd, em, strong, dfn, code, q, samp, kbd, var, cite, abbr, acronym, sub, sup, br, pre

A django site