Slide 85
Slide 85 text
DRY code
var props = ['carModel', 'carYear', 'carMiles', 'carTint'];
$('.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(props,function(i,key){
$('#input_' + key).val(checked ? defaultSettings[key] : '');
});
});