Refactored abstract method regeneration logic into a array_shrink() function
parent
d4593725a4
commit
1a9cc40c31
31
lib/class.js
31
lib/class.js
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue