Mention objects in `validate` function are passed by shallow copy. #127

Closed
fivetanley opened this Issue May 17, 2012 · 1 comment

Projects

None yet

2 participants

I just wanted to start off by saying, THANK YOU for writing this book and making it available to the public.

I think (and this is just my personal opinion) that it is important to note that Backbone passed the attributes object by shallow copy to the validate function using Underscore's _.extend function. This means that you can't change any Number or String or Boolean attribute by reference in the way that you would expect a JavaScript object to behave normally. However, because shallow copy does not copy objects by copying them, but by reference, you can change the attributes on those objects)

Example : http://jsfiddle.net/2NdDY/7/

Maybe I am the only one who thinks that attributes should be allowed to change when setting?

Is this more of an edge case? (e.g. filtering words or trimming strings)

@addyosmani addyosmani closed this in 3f2f237 Jul 7, 2012
Owner

Thanks! I've added a reference to the above for now. If we find during technical review after my planned re-write of the book that this is too much of an edge-case we might drop it but for now I think its worth keeping in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment