Add ducktyping Change.isChange method
Similar to Filter.isFilter, this should help mitigate instanceof issues.
This commit is contained in:
parent
a0fd56d7b3
commit
1d2cf79bff
|
@ -86,9 +86,21 @@ function Change(options) {
|
|||
}
|
||||
module.exports = Change;
|
||||
|
||||
Change.isChange = function isChange(change) {
|
||||
if (!change || typeof (change) !== 'object') {
|
||||
return false;
|
||||
}
|
||||
if ((change instanceof Change) ||
|
||||
((typeof (change.toBer) === 'function') &&
|
||||
(change.modification !== undefined) &&
|
||||
(change.operation !== undefined))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Change.compare = function (a, b) {
|
||||
if (!(a instanceof Change) || !(b instanceof Change))
|
||||
if (!Change.isChange(a) || !Change.isChange(b))
|
||||
throw new TypeError('can only compare Changes');
|
||||
|
||||
if (a.operation < b.operation)
|
||||
|
|
Loading…
Reference in New Issue