Please join me at my new location

Wednesday, October 17, 2007

Functions ARE Objects!

Javascript is a functional, object-oriented language - but what exactly does that mean to you a developer? It means that functions ARE objects. You can add members to functions just as you could any object. Take for example, the following function that keeps track of how many times it's been called:
function count_times() {
 count_times.call_count = (count_times.call_count || 0) + 1;
Trivial example I know, but let your imagination go wild.