Bug Tracker

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#11998 closed feature (wontfix)

Change array.length check to $.isArray

Reported by: anonymous Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: git
Keywords: Cc:
Blocked by: Blocking:

Description

I would like to propose changing makeArray to use !$.isArray(array) rather than array.length == null.

The motivation is that I use .on on instances such as file readers or file writers. That way I can take advantage of jQuery's event namespacing system, and it's a clean way of attaching events since I'm using .on for elements as well.

The issue is that FileWriters have a length property and as such jQuery recognises it as an array. Consequently, .on does not work on file writers.

I know $(someFileWriter) is perhaps not what jQuery is for, but I do think it's worth mentioning and hopefully this issue can be addressed. It would be awesome to have jQuery support .on for any instance that has addEventListener so that its event features can be used on those instances.

Change History (4)

comment:1 Changed 7 years ago by Rick Waldron

Resolution: wontfix
Status: newclosed

From the docs:

Description: Convert an array-like object into a true JavaScript array.

FileWriter is not an array-like object and the additional function call on the stack is unnecessary.

Last edited 7 years ago by Rick Waldron (previous) (diff)

comment:2 Changed 7 years ago by anonymous

I think you got me wrong.

The source of makeArray actually includes checks for e.g. functions and strings, because they are not array-like yet do have a length property. I think a similar check could be included to account for instances such as file writers.

I do not think "it's not an array-like object" is a completely valid reason, because the above checks are redundant in that case anyway. Note that I'm not talking about calling makeArray separately, but rather the call that's done when calling jQuery(something). So the change is not docs-related nor should the docs need an update.

Thanks for your response.

comment:3 Changed 7 years ago by Rick Waldron

There's a difference between testing a unit against primitives and builtins vs host APIs

comment:4 Changed 7 years ago by anonymous

Indeed, that's why I filed this request in the first place :)

Anyway, it doesn't seem like you're too intersted in feedback, so never mind.

Note: See TracTickets for help on using tickets.