Archive for January, 2009

Paying attention to your event binding in jQuery 0

When doing event binding in jQuery on a page that has a lot going on, it might be best to make sure you unbind and rebind the events, just to make sure you only get one event per element. I recently ran into an issue where the number of events triggered grew exponentially, and it was linked to this. Luckily, jQuery has a nice convention for working with rebinding. For instance, if we were binding to a button’s click event, and wanted to make sure this method was only ever called once when this button was clicked, we could do the following:

1
2
3
4
5
6
7
8
...
$("#some-button-id").unbind("click", buttonClickCallback)
    .bind("click", buttonClickCallback);
...

function buttonClickCallback(e) {
    // code for the button click event
}

This way, we explicitly remove and reset the function that will be called when that button is clicked. Inside the function body, you can still use $(this), just as you would do had you written the function inline. There are a couple of variations to the unbind method: without any arguments, it can unbind ALL bound events, and with only the event type, it will unbind all events of that type.

You can read more about bind and unbind with jQuery in the official jQuery documentation at http://docs.jquery.com.

Distracted by perfectionism 1

When it comes to working on personal software development projects, I have a problem. I’m not sure where the problem originates, but I’m pretty sure it has something to do with the lack of a hard deadline for what I’m working on and having no one else to communicate with on my project (or, lack of outside interest). The problem is a little thing called perfectionism.

When I’m at work, my mindset is on the finished project. Everything gets specced out, and if I run into trouble I break things down and try to keep the project moving. The client doesn’t want to hear stories about how I ran into difficulties with line 52 of such-and-such code file. They are wanting the product. Even on the few occasions I work from home, my mindset is still like this.

For some reason, though, when it comes to doing personal projects, for learning or just something where I am the “client,” my process breaks down. I get distracted easily and focus too heavily on the process instead of the product. My concern shifts from getting the product done to getting the product perfect, which, as much as I hate to say, is almost impossible. The result: tons of half finished projects in various languages and frameworks littering my hard drive.

I’m not afraid to admit that this is a personal discipline challenge, and it is one that I’m more than ready to face head-on. I should treat my process of handling a project the same regardless of the environment, and it should not matter if I’m doing it for myself or for a client (except for deadlines and such). One could raise the question of when is a project actually considered to be “finished,” but that’s a whole different can of worms to open, and I feel just hitting the first “finished” milestone on one of my personal projects will be a huge improvement.

If anyone else has had similar experiences and have overcome it, I would love to hear about it.