Showing posts with label closure. Show all posts
Showing posts with label closure. Show all posts

Callback that Does Its Thing on the Second Call Only

A little (javascript) closure on a lovely snowy evening in Knoxville.

There might be a better way to do this, but it seems to work.

The basic issue I ran into was that I was setting off two d3 animations, and I couldn't know which one would finish first. Whichever one finished last, I wanted something else to happen.

A solution that seems to work is to have both animations call the same callback when finished, which is set via the .each("end", callback), and on the second call to the callback do the work I wanted done.

Towards Understanding Javascript Closures

This is a short note on javascript closures. There is considerable confusion and discussion on the internet (and in my head) about these things. And some of that might be due to the word "closure" itself. For me, "enclosure" captures my current understanding a bit better.

Popular Posts