Posts from — July 2010

A useful JavaScript pattern – The Module Pattern

Introduction A good API design forms an integral part of coding best practices. And what is a good API? A good API would only expose methods that would be needed by the client using the API. The public space would not be cluttered by unnecessary methods. And there are not many times where I have seen JavaScript developers really caring about a good API design. The reason probably is that people don’t take JavaScript seriously. Anyway, that is another topic, which might require a separate blog post of its own. Module pattern So coming back to the topic, I would…

July 25, 2010   Views: 6,279   17 Comments

jQuery – Using $ with other JavaScript libraries

Although $ sounds native to jQuery alone, but there are other JavaScript libraries and frameworks as well that use $, one example is scriptaculous. But what if you want to use $ in your jQuery based code or plugin, $ sure is a very short shortcut. I will show you a nice little trick of how to do so. The trick involves writing all the code in a function and executing that function immediately: (function() { // put your code here })(); See how the function gets executed immediately, so all you need to do now to use $, is…

July 6, 2010   Views: 5,126   8 Comments

Extending jQuery – jQuery plugin development

Some introductory words. jQuery is a very popular JavaScript library and why wouldn’t it be popular, it has made the life of us developers so so easy. Its not just that our lives have become easy, but so has our code-base become more cleaner. Anyways we are not going to discuss the merits of jQuery, I will have a separate post to discuss that. Right now what I would be discussing is how to write plugins for jQuery. Two ways of extending jQuery: There are two kinds of ways that you can extend jQuery. As you probably know that methods…

July 4, 2010   Views: 11,573   11 Comments