Friday, November 20, 2009

What is a Javascript closure?

"a closure is a first-class function with free variables that are bound in the lexical environment"

"a closure is the local variables for a function - kept alive after the function has returned"

"when you pass a method reference out of the context in which it was defined, the method still has access to its parent context"

"a powerful, low level JavaScript library designed for building complex and scalable web applications"

Now the last one will be a bit harder to chew :)

Google released their internal JS library as Open Source code. And it looks sweet.

Until recently I was using Dojo for the better OOP architecture support as opposed to jQuery. Then I realized that the two serve different purposes. Now I use jQuery for augmenting my CakePHP views. It's much easier to do and you have a better chance to find a plugin to use as a base for your needed functionality.

But I wonder if Closure is better than Dojo?

From the first impression it looks that they drew a lot of inspiration from the Dojo Toolkit. Starting with the require/provide directives that instantly made me think "Dojo". I didn't get a chance to dive in yet and I'm still searching for some good online UI demos. I guess those will come soon but not from Google. I don't expect too much support from them and I suspect they'll leave the library follow it's own path once they released it into the wild.

Nevertheless Closure will be a tough player in the Javascript frameworks arena. If Gmail and Docs run on it then it's already production proven. But I guess jQuery is still better for what is normally needed in a web page. For one-page JS apps Dojo and now Chrome with their solid i18n, themes (Closure?) and templates support still rock.


Post a Comment

<< Home