DailyJS

Tracer

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

language utilities

Tracer

Posted by Alex R. Young on .
Featured

language utilities

Tracer

Posted by Alex R. Young on .

I just finished reading about Angus Croll's
tracer utility -- a tiny pure JavaScript method tracer. It traverses prototype
chains and wraps each method in a new function that calls the tracer's
code.

To understand this, remember that functions on objects can be iterated
over. Also recall that functions in JavaScript are first class objects,
which means they can be decorated with properties. Combining these two
facts allows object methods to be iterated over and safely modified to
call external code.

This can even be done recursively:

tracer.traceAll(jQuery, true)
>> tracing init
>> tracing size
>> tracing toArray
// ...

The source code is in the article: A tracer utility in
2kb
.