Rid*_*del 6 each jquery refactoring
我有这个代码块,我觉得特别长,难以理解:调用堆栈充满了隐含的函数,并且隐含地添加了参数.换句话说,我想通过将每个中调用的函数与每个函数分开来澄清我的代码.
看那个例子:
$(xml).find('group').each(function () {
var groupName = $(this).attr('name');
// There is here around 100 lines of codes I would like to split in
// at least five functions, And I'm sure it is possible to use named functions
// instead of implicit ones, no ?
Run Code Online (Sandbox Code Playgroud)
尝试传递函数引用
$(xml).find('group').each(myfun);
function myfun(i, item)
{
alert(item.id);
}
Run Code Online (Sandbox Code Playgroud)