yui-core.js revision 69a063b45ae500a0e28f869ad728378d36fbe9e6
/**
* The YUI module contains the components required for building the YUI
* seed file. This includes the script loading mechanism, a simple queue,
* and the core utilities for the library.
* @module yui
* @submodule yui-base
*/
var CACHED_DELIMITER = '__',
/**
* Returns a new object containing all of the properties of
* all the supplied objects. The properties from later objects
* will overwrite those in earlier objects. Passing in a
* single object will create a shallow copy of it. For a deep
* copy, use clone.
* @method merge
* @for YUI
* @param arguments {Object*} the objects to merge.
* @return {object} the new merged object.
*/
Y.merge = function() {
for (i = 0; i < l; i = i + 1) {
Y.mix(o, a[i], true);
}
return o;
};
/**
* Mixes _supplier_'s properties into _receiver_. Properties will not be
* overwritten or merged unless the _overwrite_ or _merge_ parameters are
* `true`, respectively.
*
* In the default mode (0), only properties the supplier owns are copied
* (prototype properties are not copied). The following copying modes are
* available:
*
* - `0`: _Default_. Object to object.
* - `1`: Prototype to prototype.
* - `2`: Prototype to prototype and object to object.
* - `3`: Prototype to object.
* - `4`: Object to prototype.
*
* @method mix
* @param {Function|Object} receiver The object or function to receive the mixed
* properties.
* @param {Function|Object} supplier The object or function supplying the
* properties to be mixed.
* @param {Boolean} [overwrite=false] If `true`, properties that already exist
* on the receiver will be overwritten with properties from the supplier.
* @param {String[]} [whitelist] An array of property names to copy. If
* specified, only the whitelisted properties will be copied, and all others
* will be ignored.
* @param {Int} [mode=0] Mix mode to use. See above for available modes.
* @param {Boolean} [merge=false] If `true`, objects and arrays that already
* supplier merged into them, rather than being skipped or overwritten. When
* both _overwrite_ and _merge_ are `true`, _merge_ takes precedence.
* @return {Function|Object|YUI} The receiver, or the YUI instance if the
* specified receiver is falsy.
*/
// If no supplier is given, we return the receiver. If no receiver is given,
// we return Y. Returning Y doesn't make much sense to me, but it's
// grandfathered in for backcompat reasons.
return receiver || Y;
}
if (mode) {
// In mode 2 (prototype to prototype and object to object), we recurse
// once to do the proto to proto mix. The object to object mix will be
// handled later on.
if (mode === 2) {
}
// Depending on which mode is specified, we may be copying from or to
// the prototypes of the supplier and receiver.
// If either the supplier or receiver doesn't actually have a
// prototype property, then we could end up with an undefined `from`
// or `to`. If that happens, we abort and return the receiver.
return receiver;
}
} else {
}
// If `overwrite` is truthy and `merge` is falsy, then we can skip a call
// to `hasOwnProperty` on each iteration and save some time.
if (whitelist) {
// We call `Object.prototype.hasOwnProperty` instead of calling
// `hasOwnProperty` on the object itself, since the object's
// `hasOwnProperty` method may have been overridden or removed.
// Also, some native objects don't implement a `hasOwnProperty`
// method.
continue;
}
// If we're in merge mode, and the key is present on both
// objects, and the value on both objects is either an object or
// an array (but not a function), then we recurse to merge the
// `from` value into the `to` value instead of overwriting it.
// We're not in merge mode, so we'll only copy the `from` value
// to the `to` value if we're in overwrite mode or if the
// current key doesn't exist on the `to` object.
}
}
} else {
// The code duplication here is for runtime performance reasons.
// Combining whitelist and non-whitelist operations into a single
// loop or breaking the shared logic out into a function both result
// in worse performance, and Y.mix is critical enough that the byte
// tradeoff is worth it.
continue;
}
}
}
// If this is an IE browser with the JScript enumeration bug, force
// enumeration of the buggy properties by making a recursive call with
// the buggy properties as the whitelist.
if (Y.Object._hasEnumBug) {
}
}
return receiver;
};
/**
* Returns a wrapper for a function which caches the
* return value of that function, keyed off of the combined
* argument values.
* @method cached
* @param source {function} the function to memoize.
* @param cache an optional cache seed.
* @param refetch if supplied, this value is tested against the cached
* value. If the values are equal, the wrapped function is executed again.
* @return {Function} the wrapped function.
*/
return function(arg1) {
}
return cache[k];
};
};