jashkenas/backbone — pull request #3181 by suprememoocow (2014-06-06 12:51:49+00:00)
Title: Allow users to override `isEqual` method

This PR allows customisation of the isEqual method used by Backbone. Currently this is hard-wired to be underscore's isEqual method. This PR allows the application developer to configure a new method through `Backbone.isEqual`, with the default as `_.isEqual`

### Why would you want to do this?
We're using momentjs for dates, and these dates are stored in our Backbone Models. Unfortunately the default deep equals strategy used by backbone doesn't handle moment dates very well, so two equal dates may seem to be different, causing additional change events to fire unnecessarily.

This problem can be generalised to any Backbone attributes that consist of objects in which the internal state does not represent the external state of the object, such as any object that keeps a cache which may or may not be populated.

As an example

```
function CustomObject(value) {
this.value == value;
}
CustomObject.prototype.format = function() {
if(this._formatMethod) {
this._formatMethod = ... // Create an object
}
return this._formatMethod(this.value);
}

var c = new CustomObject(1);
var d = new CustomObject(1);

_.isEqual(c, d) -> true

d.format();
_.isEqual(c, d) -> false
```

Allowing the application developer to override the equality method means that they can deal with this type of situation in their code.