I can’t remember for the life of me where I learning this trick from, but I thought I’d share it nonetheless. I’ve been using it quite frequently recently so it’s at the forefront of my thoughts.
Take this block of jQuery code as an example:
$(document).ready(function(){
$('#sortable').sortable({
placeholder: 'ui-state-highlight',
delay: 250,
axis: 'y',
handle: 'a.move'
});
});
This particular function inside of a jQuery extension allows for multiple parameters/options to be passed to the function to extend the functionality in the browser. There are quite a few possible parameters, but here I’ve also used 4.
One of the quickest ways for me to add a new line sometimes is to simply copy a line from above and change the property and value. But I’ve run into a few situations where a stray comma left on the last line caused the entire function to break. (Thanks a lot Internet Exploder.) Also, did I miss a comma? It’s hard to tell by just glancing over the lines.
So what I’ve been doing is placing the comma at the front of the line. To me, it actually is a little bit easier to read and when I copy down a line I don’t have to worry about stray characters breaking the script.
$(document).ready(function(){
$('#sortable').sortable({
placeholder: 'ui-state-highlight'
, delay: 250
, axis: 'y'
, handle: 'a.move'
});
});
What do you think? Do you like the commas at the beginning or the end of the line?










