method modifiers in addition to "bind"

Peter Seliger peter.seliger at
Thu Feb 16 05:30:50 PST 2012

On Thu, Feb 16, 2012 at 9:38 AM, David Bruant <bruant.d at> wrote:
> Is there a widespread use of such constructs in JavaScript? I can't recall
> having seen such things.

It comes closest to Malte Ubl's JavaScript Meta Object System "JOOSE".
"before", "after" and "around" are optional keywords of a configuration
object that describes e.g. "Joose" classes or "Joose" roles.
Resolving conflicts of equally named (homonymic?) methods at construction
time is theirs main purpose.

> Can you show some examples of what it would look like?

Joose examples can be found at

A prototypal implementation of that trio might look like this attempt of mine

I recently did make use of "around" a lot in order to specialize
a generic view component depending on its DOM environment and the
device that runs it.

This view component is a singleton module that transforms DOM
structures. But it does not transform plainly. A properly rendered
view relies on DOM measurements and the transformation itself
shall only take place within specific environments.

"transformDOMStructure" was this modules sole public method.

But in order to keep this components source code unchanged and also
ensuring the above mentioned flexibility I could shape out what AOP
seems to call "Cross Cutting Point"s (CCP).

"isTransformDOMStructure" and "getDOMMeasurementsOfCurrentView" now are
two additional public methods that get used by "transformDOMStructure".

Definitions of whether a certain transformation should take place or
not as well as descriptions of how to measure a certain DOM-Fragment
now can be written into contollers/presenters that, in my understanding
of AOP, also could be called aspects (of this generic util).
Such a controller has to provide code that wraps additional functionality
around both methods that got identified as CCPs.

myUtil.isTransformDOMStructure =
myUtil.isTransformDOMStructure.around(function (


) {

// ... specification.

}/*, target*/);

"around" creates a wrapper that has access to the former method ("...Enclosed"),
to itself ("...Around" - in case there is need of it), to the "arguments" object
of the initial function call and to "target" that, optionally can be provided
as second parameter to "around".

A second use case was this often mentioned "logging". By walking a globally
namespaced 3rd party library recursively whilst wrapping every function object
it was easy to log a methods name, its object path and all of its arguments.


More information about the es-discuss mailing list