jaredatch/Custom-Metaboxes-and-Fields-for-WordPress — Issue #74: Avoid anonymous script functions
Author: GaryJones
Created: 2011-12-31 17:37:18+00:00
State: open

The CMB scripts currently make use of a lot of anonymous functions. While not bad per se, they could be better.

Named functions allow for better self-documenting code - a function named "removeFileButton()" is clearer about its purpose than:

```
function() {
formfield = $(this).attr('rel');
$('input#' + formfield).val('');
$('input#' + formfield + '_id').val('');
$(this).parent().remove();
return false;
}
```

Named functions also allow for code re-use, and several named functions that are similar might be able to be refactored into one function.

Standalone functions can also be better documented with JSDoc, making it explicit what the function is for, what parameter types are expected, and what the return type is going to be.