Created
June 16, 2010 04:03
-
-
Save javajosh/440144 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The Otter Style of JavaScript | |
//(Because you 'otter' name your functions) | |
//Which one is more expressive? | |
$('tr').click(function (){ | |
var $form = $(this).closest('div').find('form'); | |
$('td', this).each(function (i){ | |
if (i === 0) return; | |
$('input', $form).eq(i-1).val(this.innerHTML); | |
}); | |
}); | |
//vs. | |
$('tr').click(function rowClicked(){ | |
var $form = $(this).closest('div').find('form'); | |
$('td', this).each(function populateForm(i){ | |
if (i === 0) return; | |
$('input', $form).eq(i-1).val(this.innerHTML); | |
}); | |
}); | |
//=================================== | |
//Or how about this | |
$(this).parent().hover( | |
function() {}, | |
function(){ $(this).parent().find("ol").slideUp('medium'); } | |
); | |
//vs this? | |
$(this).parent().hover( | |
function hoverin() {}, | |
function hoverout(){ $(this).parent().find("ol").slideUp('medium'); } | |
); | |
//=================================== | |
//And this makes me feel good inside. | |
$(function main(){ | |
alert('Hello world'); | |
}); | |
//=================================== | |
//One question you might ask is, does this pollute the namespace? Let's see: | |
var foo = function(){console.info('foo');} | |
var bar = function foo(){console.info('bar');} | |
foo(); | |
bar(); | |
//Nope. We're good. | |
//Okay, not entirely good. This statement | |
var baz = function foo(){console.info('baz');foo();} | |
baz(); | |
/*goes infinite, rather than print "bar, foo" | |
as you might expect. The outer foo is masked | |
by the local function name. However, I don't | |
see this as a big deal, so I'll keep doing | |
it (until it's a big deal).*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment