angular-object-diff.js
function diff(a, b, shallow, isOwn) {

            if (a === b) {
                return equalObj(a);
            }

            var diffValue = {};
            var equal = true;

            for (var key in a) {
                if ((!isOwn && key in b) || (isOwn && typeof b != 'undefined' && b.hasOwnProperty(key))) {
                    if (a[key] === b[key]) {
                        diffValue[key] = equalObj(a[key]);
                    } else {
                        if (!shallow && isValidAttr(a[key], b[key])) {
                            var valueDiff = diff(a[key], b[key], shallow, isOwn);
                            if (valueDiff.changed == 'equal') {
                                diffValue[key] = equalObj(a[key]);
                            } else {
                                equal = false;
                                diffValue[key] = valueDiff;
                            }
                        } else {
                            equal = false;
                            diffValue[key] = {
                                changed: 'primitive change',
                                removed: a[key],
                                added: b[key]
                            }
                        }
                    }
                } else {
                    equal = false;
                    diffValue[key] = {
                        changed: 'removed',
                        value: a[key]
                    }
                }
            }

            for (key in b) {
                if ((!isOwn && !(key in a)) || (isOwn && typeof a != 'undefined' && !a.hasOwnProperty(key))) {
                    equal = false;
                    diffValue[key] = {
                        changed: 'added',
                        value: b[key]
                    }
                }
            }

            if (equal) {
                return equalObj(a);
            } else {
                return {
                    changed: 'object change',
                    value: diffValue
                }
            }
        }
function diff(a, b, shallow, isOwn) {

            if (a === b) {
                return equalObj(a);
            }

            var diffValue = {};
            var equal = true;

            for (var key in a) {
                if ((!isOwn && key in b) || (isOwn && typeof b != 'undefined' && b.hasOwnProperty(key))) {
                    if (a[key] === b[key]) {
                        diffValue[key] = equalObj(a[key]);
                    } else {
                        if (!shallow && isValidAttr(a[key], b[key])) {
                            var valueDiff = diff(a[key], b[key], shallow, isOwn);
                            if (valueDiff.changed == 'equal') {
                                diffValue[key] = equalObj(a[key]);
                            } else {
                                equal = false;
                                diffValue[key] = valueDiff;
                            }
                        } else {
                            equal = false;
                            diffValue[key] = {
                                changed: 'primitive change',
                                removed: a[key],
                                added: b[key]
                            }
                        }
                    }
                } else {
                    equal = false;
                    diffValue[key] = {
                        changed: 'removed',
                        value: a[key]
                    }
                }
            }

            for (key in b) {
                if ((!isOwn && !(key in a)) || (isOwn && typeof a != 'undefined' && !a.hasOwnProperty(key))) {
                    equal = false;
                    diffValue[key] = {
                        changed: 'added',
                        value: b[key]
                    }
                }
            }

            if (equal) {
                return equalObj(a);
            } else {
                return {
                    changed: 'object change',
                    value: diffValue
                }
            }
        }
function diff ( a , b , shallow , isOwn ) { if ( a === b ) { return equalObj ( a ) ; } var diffValue = { } ; var equal = true ; for ( var key in a ) { if ( ( ! isOwn && key in b ) || ( isOwn && typeof b != 'undefined' && b . hasOwnProperty ( key ) ) ) { if ( a [ key ] === b [ key ] ) { diffValue [ key ] = equalObj ( a [ key ] ) ; } else { if ( ! shallow && isValidAttr ( a [ key ] , b [ key ] ) ) { var valueDiff = diff ( a [ key ] , b [ key ] , shallow , isOwn ) ; if ( valueDiff . changed == 'equal' ) { diffValue [ key ] = equalObj ( a [ key ] ) ; } else { equal = false ; diffValue [ key ] = valueDiff ; } } else { equal = false ; diffValue [ key ] = { changed : 'primitive change' , removed : a [ key ] , added : b [ key ] } } } } else { equal = false ; diffValue [ key ] = { changed : 'removed' , value : a [ key ] } } } for ( key in b ) { if ( ( ! isOwn && ! ( key in a ) ) || ( isOwn && typeof a != 'undefined' && ! a . hasOwnProperty ( key ) ) ) { equal = false ; diffValue [ key ] = { changed : 'added' , value : b [ key ] } } } if ( equal ) { return equalObj ( a ) ; } else { return { changed : 'object change' , value : diffValue } } }
diff between object a and b
@param {Object} a
@param {Object} b
@param shallow
@param isOwn
@return {Object}
diff between object a and b