View Full Version : [CLOSED] Ext.iterate - incorrect input check

2 May 2013, 10:21 AM
I'd like point out that the input check is good for empty arrays but it will not work on empty objects.

Ext.isEmpty({}) returns false. Ext.Object.isEmpty({}) returns true.

* Iterates either an array or an object. This method delegates to
* {@link Ext.Array#each Ext.Array.each} if the given value is iterable, and {@link Ext.Object#each Ext.Object.each} otherwise.
* @param {Object/Array} object The object or array to be iterated.
* @param {Function} fn The function to be called for each iteration. See and {@link Ext.Array#each Ext.Array.each} and
* {@link Ext.Object#each Ext.Object.each} for detailed lists of arguments passed to this function depending on the given object
* type that is being iterated.
* @param {Object} scope (Optional) The scope (`this` reference) in which the specified function is executed.
* Defaults to the object being iterated itself.
* @markdown
iterate: function(object, fn, scope) {
if (Ext.isEmpty(object)) { // <--- this check will not work for an empty object

if (scope === undefined) {
scope = object;

if (Ext.isIterable(object)) {
Ext.Array.each.call(Ext.Array, object, fn, scope);
else {
Ext.Object.each.call(Ext.Object, object, fn, scope);

2 May 2013, 1:43 PM
Detecting an "empty" object isn't quite as straight forward as an array. As it goes, it makes no functional difference in the code.