Backbone.js ↔ Underscore.js: Deep Comparison Compatibility in Model#set
0 reputation · 24 Apr 2024, 23:10 UTC
Backbone.js ↔ Underscore.js: Deep Comparison Compatibility in Model#set
Backbone’s Model#set relies on Underscore’s _.isEqual to detect attribute changes. The 1.9 release of Underscore introduced stricter deep‑comparison semantics, causing Backbone to flag a change when only a nested property is modified, even if the top‑level reference remains the same. This can trigger spurious change events or, conversely, hide necessary updates in collections.
Because Backbone 1.4+ performs no explicit version check on Underscore, projects that upgrade Underscore without reviewing release notes may experience silent regressions. The community has not agreed on whether Backbone should embed its own comparison logic or continue to depend on an evolving external library.
What are the trade‑offs of each approach? Should Backbone provide a fallback for legacy _.isEqual behavior, or is overriding the comparator in Model#set the safest path? How can developers test for unintended change events when upgrading Underscore in an existing Backbone codebase?