Cunning closures

<![CDATA[I just wrote a nifty bit of Javascript to allow nested lists to be displayed as a tree with little buttons to hide and show parts. It's incredibly simple to use. Firstly include the javascript file with a script tag (obviously). Then put a span element around the list you want to be undisplayable that has the class tree (in fact it can be element with the correct class).

The clever bit (for me at least) is that it uses a closure to do this. Explaining what a closure is is difficult to do quickly but it involves a function returning a function that is altered by the values passed to the function (the first one).

It’s being used right now to in my sidebar to display “pages”.

Javascript, programming, closure, scripts, ECMAScript]]>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s