ColdFusioning.com
Pronunciation \kold-fy-zhn-ing\ Noun: The actions of one that writes ColdFusion.

Please check out my new site: http://ja.mesbrown.com/

jQuery Document Ready Shortcut

Here's a quick tip. Instead of writing:

view plain print about
1$(document).ready(function() {
2// Code and functions here
3});

We can instead write:
view plain print about
1$().ready(function() {
2// Code and functions here
3});

or even:
view plain print about
1$(function() {
2// Code and functions here
3});

Albeit, it isn't a huge code reduction but it is a nice shortcut.

TweetBacks

Comments

I like that we can use these shortcuts in jQuery, however, I am hesitant to use them. Why? Well, because I think the original way is easier for someone not well versed in jQuery to figure out what is going on.

We never know who will need to work on our code and I strive to make sure that my code is easy to understand and 'figure out' even if you do not know exactly what is going on.

# Posted By Scott Stroz | 10/26/09 10:02 AM

I'm in the same boat as Scott - those shortcuts are -real- weird if you are a newbie. :)

# Posted By Raymond Camden | 10/26/09 11:28 AM

Would you both advocate not using them at all or maybe put a comment before the first one to explain and educate the user?

# Posted By James Brown | 10/26/09 11:38 AM

Oh I wouldn't advocate against it- I just wouldn't use it -myself-. And in a team environment I'd be cognizant of the skill levels of the other team members.

Nothing more than that really.

# Posted By Raymond Camden | 10/26/09 11:40 AM

Recent Comments

RSS

Subscribe