Slide 18
Slide 18 text
DRY-er code
/*Dry*/
$('.someCheckbox').click(function(){
var checked = this.checked;
/*
What are we repeating?
1. input_ precedes each field name
2. accessing the same array for settings
3. repeating value resets
What can we do?
1. programmatically generate the field names
2. access array by key
3. merge this call using terse coding (ie. if checked,
set a value, otherwise don't)
*/
$.each(['carModel', 'carYear', 'carMiles', 'carTint'], function(i,key){
$('#input_' + v).val(checked ? defaultSettings[key] : '');
});
});