Skip to main content

Bug Tracker

Side navigation

#3026 closed enhancement (duplicate)

Opened June 11, 2008 06:55PM UTC

Closed August 12, 2008 07:38PM UTC

More robust jQuery.makeArray

Reported by: arrix Owned by: flesler
Priority: minor Milestone: 1.3
Component: core Version: 1.2.6
Keywords: Cc: arrix
Blocked by: Blocking:

Currently, makeArray() uses to determine whether array is a function, which fails with scripts that define

makeArray: function( array ) {
	var ret = [];

	if( array != null ){
		var i = array.length;
		//the window, strings and functions also have 'length'
		if( i == null || array.split || array.setInterval || )
			ret[0] = array;
			while( i )
				ret[--i] = array[i];

	return ret;

Unfortunately, there are quite a few scripts do so, notably, effect.js (an old version)

Search for

Is it OK to use jQuery.isFunction(array) instead of a simple property test?

If jQuery.isFunction() introduces too much overhead, we can also use something like typeof array == 'function'.

Instead of testing whether array is not an Array, we can also test whether it is an Array.

e.g. if (array && array.length && array.splice && array.join)

This may seem unnecessary if the developer has full control of all javascript code but it makes jQuery more robust (good for bookmarklets and greasemonkey scripts).

Attachments (0)
Change History (4)

Changed June 11, 2008 10:06PM UTC by flesler comment:1

owner: → flesler
priority: majorminor
status: newassigned
type: bugenhancement

There are many different types of collections that must be treated as arrays.

Arrays, arguments, nodelists, jQuery, form.elements, {length:1, '0':'a'} and probably more.

Testing positively for arrays would make it impossible to handle all this.

Using isFunction does seem like too much overhead for me.

This was already "scheduled for improvement". Will work on it asap, for the next release.

Changed July 23, 2008 04:29PM UTC by flesler comment:2

resolution: → wontfix
status: assignedclosed

The only known conflict is with Scriptaculous.

But they changed they removed call from Array's prototype since 1.8.

So upgrading solves the problem, no need for a hack on our side.

Changed August 12, 2008 07:38PM UTC by flesler comment:3

resolution: wontfix
status: closedreopened

Changed August 12, 2008 07:38PM UTC by flesler comment:4

cc: → arrix
resolution: → duplicate
status: reopenedclosed

This has been taken into account in the end. Fixed at [5825].