* @ngdoc function * @name angular.equals * @module ng * @kind function * * @description * Determines if two objects or two values are equivalent. Supports value types, regular * expressions, arrays and objects. * * Two objects or values are considered equivalent if at least one of the follo
(o1, o2)
| 977 | * @returns {boolean} True if arguments are equal. |
| 978 | */ |
| 979 | function equals(o1, o2) { |
| 980 | if (o1 === o2) return true; |
| 981 | if (o1 === null || o2 === null) return false; |
| 982 | if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN |
| 983 | var t1 = typeof o1, t2 = typeof o2, length, key, keySet; |
| 984 | if (t1 == t2) { |
| 985 | if (t1 == 'object') { |
| 986 | if (isArray(o1)) { |
| 987 | if (!isArray(o2)) return false; |
| 988 | if ((length = o1.length) == o2.length) { |
| 989 | for(key=0; key<length; key++) { |
| 990 | if (!equals(o1[key], o2[key])) return false; |
| 991 | } |
| 992 | return true; |
| 993 | } |
| 994 | } else if (isDate(o1)) { |
| 995 | if (!isDate(o2)) return false; |
| 996 | return (isNaN(o1.getTime()) && isNaN(o2.getTime())) || (o1.getTime() === o2.getTime()); |
| 997 | } else if (isRegExp(o1) && isRegExp(o2)) { |
| 998 | return o1.toString() == o2.toString(); |
| 999 | } else { |
| 1000 | if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) || isArray(o2)) return false; |
| 1001 | keySet = {}; |
| 1002 | for(key in o1) { |
| 1003 | if (key.charAt(0) === '$' || isFunction(o1[key])) continue; |
| 1004 | if (!equals(o1[key], o2[key])) return false; |
| 1005 | keySet[key] = true; |
| 1006 | } |
| 1007 | for(key in o2) { |
| 1008 | if (!keySet.hasOwnProperty(key) && |
| 1009 | key.charAt(0) !== '$' && |
| 1010 | o2[key] !== undefined && |
| 1011 | !isFunction(o2[key])) return false; |
| 1012 | } |
| 1013 | return true; |
| 1014 | } |
| 1015 | } |
| 1016 | } |
| 1017 | return false; |
| 1018 | } |
| 1019 | |
| 1020 | var csp = function() { |
| 1021 | if (isDefined(csp.isActive_)) return csp.isActive_; |
no test coverage detected