-
Notifications
You must be signed in to change notification settings - Fork 422
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
Unexpected behaviour while using a Map #667
Comments
This is expected behavior. You read that property like: "my.item". Sent from my iPhone
|
I think this might be broken only when the value you are trying to retrieve is falsey. |
Precisely @thecountofzero , there appears to be a check for "." and then to return that element if it is found. But the check is only if it's truthy, this is very odd behaviour, shouldn't it be one or the other? @justinbmeyer The Attr functionality currently works like this var result, test = new can.Model({
'my.enable': false,
'my.item': true,
'my.count': 0,
'my.newCount': 1
});
result = test.attr('my.enable'); // result === undefined
result = test.attr('my.item'); // result === true
result = test.attr('my.count'); // result === undefined
result = test.attr('my.newCount'); // result === 1 That doesn't feel right to me. |
Use the "." Sent from my iPhone
|
Using the "." works, but if the value of the attribute you are retrieving is a falsey value, it returns "undefined". |
Getting a falsey value should probably not work without the "". |
Really, if you can escape the |
Getting a falsey value fails with the "" |
That's why I reopened. It's really inconsistent. And broken for falsy values. |
Out of interest, isn't it true that in javascript "\.there's a dot\." === ".there's a dot." So at the point we do the check the backslash is irrelevant? https://github.com/bitovi/canjs/blob/master/map/map.js#L648.. |
Fixed with #671. |
I believe I've encountered a bug/unexpected behaviour while trying to access the property of a Model. Say we have a model/map that looks like:
and we access it by
then result is === undefined, instead of false.
I have a small change in mind which will resolve this issue, by making a change to this check https://github.com/bitovi/canjs/blob/master/map/map.js#L647 .
I have this ready for pull request, unless of course this is expected :)
I have reproduced it in this fiddle http://jsfiddle.net/qd73h/1/.
The text was updated successfully, but these errors were encountered: