diff --git a/lib/class.js b/lib/class.js index 99acddb..57bd48d 100644 --- a/lib/class.js +++ b/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 ) { - // 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 method = abstract_methods[ i ]; - if ( method === undefined ) - { - continue; - } + result_data.abstractMethods = array_shrink( abstract_methods ); + } +} - methods_new.push( method ); + +/** + * 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 arr_new = []; + for ( var i = 0, len = items.length; i < len; i++ ) + { + var item = items[ i ]; + if ( item === undefined ) + { + continue; } - result_data.abstractMethods = methods_new; + arr_new.push( item ); } + + return arr_new; }