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

Error parsing bindings with length attribute #124

Open
jekuno opened this issue Jul 2, 2015 · 1 comment
Open

Error parsing bindings with length attribute #124

jekuno opened this issue Jul 2, 2015 · 1 comment

Comments

@jekuno
Copy link

jekuno commented Jul 2, 2015

There's a bug in Epoxy with model attributes called length.

Let's say I have an app which stores measures of vegetables e.g. weight and length.
The default Epoxy setup doesn't work:
http://jsfiddle.net/7dddfuh8/0/

The error message in the provided example:

uncaught exception: Error parsing bindings: "value:weight,events:['keyup']"
ReferenceError: weight is not defined

The same setup works when renaming all length attributes:
http://jsfiddle.net/7dddfuh8/1/

@jekuno
Copy link
Author

jekuno commented Dec 10, 2015

I suppose this issue is caused by the underscore library which is used by epoxy. Collection function such as _.each and _.map internally use an isArrayLike function which uses duck-typing to identify array like objects by looking for a length attribute.

This is what the documentation of http://underscorejs.org/#each says:
Collection functions work on arrays, objects, and array-like objects such as arguments, NodeList and similar. But it works by duck-typing, so avoid passing objects with a numeric length property.

I worked around this issue by renaming the length attribute. What do you think about adding an according hint to the documentation?

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

No branches or pull requests

1 participant