Code and comment cleanup in the ve module

Change-Id: Ifec72c3992db2ad222a1a89c5172d4089afd865b
This commit is contained in:
Trevor Parscal 2012-06-28 03:53:15 -07:00
parent f995fc025a
commit d12beec67b

View file

@ -160,10 +160,14 @@ ve.compareObjects = function( a, b, asymmetrical ) {
* @method * @method
* @param {Array} a First array to compare * @param {Array} a First array to compare
* @param {Array} b Second array to compare * @param {Array} b Second array to compare
* @param {Boolean} [compareObjects] If true, use ve.compareObjects() to compare objects, otherwise use === * @param {Boolean} [objectsByValue] Use ve.compareObjects() to compare objects instead of ===
*/ */
ve.compareArrays = function( a, b, compareObjects ) { ve.compareArrays = function( a, b, objectsByValue ) {
var i, aValue, bValue, aType, bType; var i,
aValue,
bValue,
aType,
bType;
if ( a.length !== b.length ) { if ( a.length !== b.length ) {
return false; return false;
} }
@ -172,11 +176,22 @@ ve.compareArrays = function( a, b, compareObjects ) {
bValue = b[i]; bValue = b[i];
aType = typeof aValue; aType = typeof aValue;
bType = typeof bValue; bType = typeof bValue;
if ( aType !== bType || !( if (
( ve.isArray( aValue ) && ve.isArray( bValue ) && ve.compareArrays( aValue, bValue ) ) || aType !== bType ||
( compareObjects && ve.isPlainObject( aValue ) && ve.compareObjects( aValue, bValue ) ) || !(
(
ve.isArray( aValue ) &&
ve.isArray( bValue ) &&
ve.compareArrays( aValue, bValue )
) ||
(
objectsByValue &&
ve.isPlainObject( aValue ) &&
ve.compareObjects( aValue, bValue )
) ||
aValue === bValue aValue === bValue
) ) { )
) {
return false; return false;
} }
} }
@ -232,8 +247,14 @@ ve.copyObject = function( source ) {
}; };
/** /**
* Splice one array into another. This is the equivalent of arr.splice( offset, remove, d1, d2, d3, ... ) * Splice one array into another.
* except that d1, d2, d3, ... are specified as an array rather than separate parameters. *
* This is the equivalent of arr.splice( offset, remove, d1, d2, d3, ... ) except that arguments are
* specified as an array rather than separate parameters.
*
* This method has been proven to be faster than using slice and concat to create a new array, but
* performance tests should be conducted on each use of this method to verify this is true for the
* particular use. Also, browsers change fast, never assume anything, always test everything.
* *
* @static * @static
* @method * @method