Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ember.isArray will not detect plain object with length property #12761

Closed

Conversation

tragiclifestories
Copy link

To fix #12738 and #12688

This is a backwards incompatible change (if someone was relying on this test returning true for an object that happened to have a length property), but the old behaviour is surprising and out of line with native Array.isArray implementations, lodash.isArray and so on.

@cibernox
Copy link
Contributor

I'd say that this is not desired behaviour. An object having a length property is not enough to be considered an array-like object.

Neither Array.isArray({ length: 1 }) not _.isArray({ length: 1 }) return true.

@tragiclifestories
Copy link
Author

@cibernox That is what this change is supposed to achieve; the current behaviour of isArray will pass for {length: 1}.

@cibernox
Copy link
Contributor

Oh, I understood it the other way around. My bad. In that case seems reasoable, but a breaking change in such a basic method is delicate.

@cibernox
Copy link
Contributor

Id say that an aray-like object should be any object where typeof [Symbol.iterator] === function, but I guess that this is not cross-browser yet.

@tragiclifestories
Copy link
Author

Indeed. I wouldn't have worked on it if the mood music in the issues linked hadn't been of a 'hell with it, go ahead' kind of tone. And yes, it would have been nice to have a Ruby/Python style iterable interface like 10 years ago, but we are where we are ... :-)

@tamzinblake
Copy link

We just spotted this rather unexpected behavior - is there any movement on this PR?

@tragiclifestories
Copy link
Author

@thomblake tbh I'd almost forgotten about it myself.

@mixonic
Copy link
Member

mixonic commented Jun 26, 2016

I'm closing this in favor of the approach taken by #12708. That seems to handle the root cause error, that fileList is considered an object, a bit better. Please let me know if I might be missing something though. Thanks!

@mixonic mixonic closed this Jun 26, 2016
@tragiclifestories
Copy link
Author

@mixonic Well, I still think this is unexpected behaviour. Eg, say I have a Product class, which has separate size properties for depth, width and length. I would not want ember to assume that instances of this class were iterable.

@tamzinblake
Copy link

Yeah we also encountered this in a different context and it was really surprising.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Objects with a length property of 0 evaluate to false in handlebars conditionals
5 participants