Refactored abstract method regeneration logic into a array_shrink() function
parent
d4593725a4
commit
1a9cc40c31
31
lib/class.js
31
lib/class.js
|
@ -206,23 +206,40 @@ function prop_copy( props, dest, result_data )
|
||||||
// should we regenerate the array of abstract methods (this must be done
|
// should we regenerate the array of abstract methods (this must be done
|
||||||
// because the length of the array remains the same after deleting elements)
|
// because the length of the array remains the same after deleting elements)
|
||||||
if ( abstract_regen )
|
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
|
// copy the methods into a new array by pushing them onto it, to ensure
|
||||||
// the length property of the array will work properly
|
// the length property of the array will work properly
|
||||||
var methods_new = [];
|
var arr_new = [];
|
||||||
for ( var i = 0, len = abstract_methods.length; i < len; i++ )
|
for ( var i = 0, len = items.length; i < len; i++ )
|
||||||
{
|
{
|
||||||
var method = abstract_methods[ i ];
|
var item = items[ i ];
|
||||||
if ( method === undefined )
|
if ( item === undefined )
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
methods_new.push( method );
|
arr_new.push( item );
|
||||||
}
|
}
|
||||||
|
|
||||||
result_data.abstractMethods = methods_new;
|
return arr_new;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue