1
0
Fork 0

Refactored abstract method regeneration logic into a array_shrink() function

closure/master
Mike Gerwitz 2010-11-14 21:39:46 -05:00
parent d4593725a4
commit 1a9cc40c31
1 changed files with 29 additions and 12 deletions

View File

@ -207,22 +207,39 @@ function prop_copy( props, dest, result_data )
// because the length of the array remains the same after deleting elements)
if ( abstract_regen )
{
result_data.abstractMethods = array_shrink( abstract_methods );
}
}
/**
* Shrinks an array, removing undefined elements
*
* Pushes all items onto a new array, removing undefined elements. This ensures
* that the length of the array represents correctly the number of elements in
* the array.
*
* @param {Array} items array to shrink
*
* @return {Array} shrunken array
*/
function array_shrink( items )
{
// copy the methods into a new array by pushing them onto it, to ensure
// the length property of the array will work properly
var methods_new = [];
for ( var i = 0, len = abstract_methods.length; i < len; i++ )
var arr_new = [];
for ( var i = 0, len = items.length; i < len; i++ )
{
var method = abstract_methods[ i ];
if ( method === undefined )
var item = items[ i ];
if ( item === undefined )
{
continue;
}
methods_new.push( method );
arr_new.push( item );
}
result_data.abstractMethods = methods_new;
}
return arr_new;
}