diff --git a/src/Angular.js b/src/Angular.js index 87bce33cca96..559c6362f97e 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -399,6 +399,10 @@ function toInt(str) { return parseInt(str, 10); } +var isNumberNaN = Number.isNaN || function isNumberNaN(num) { + return num !== num; +}; + function inherit(parent, extra) { return extend(Object.create(parent), extra); @@ -1113,7 +1117,7 @@ function fromJson(json) { function timezoneToOffset(timezone, fallback) { var requestedTimezoneOffset = Date.parse('Jan 01, 1970 00:00:00 ' + timezone) / 60000; - return isNaN(requestedTimezoneOffset) ? fallback : requestedTimezoneOffset; + return isNumberNaN(requestedTimezoneOffset) ? fallback : requestedTimezoneOffset; } diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index e59ae067582d..e64bc3cfbc54 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1259,7 +1259,7 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) { if (isDefined(val) && !isNumber(val)) { val = parseFloat(val, 10); } - minVal = isNumber(val) && !isNaN(val) ? val : undefined; + minVal = !isNumberNaN(val) ? val : undefined; // TODO(matsko): implement validateLater to reduce number of validations ctrl.$validate(); }); @@ -1275,7 +1275,7 @@ function numberInputType(scope, element, attr, ctrl, $sniffer, $browser) { if (isDefined(val) && !isNumber(val)) { val = parseFloat(val, 10); } - maxVal = isNumber(val) && !isNaN(val) ? val : undefined; + maxVal = !isNumberNaN(val) ? val : undefined; // TODO(matsko): implement validateLater to reduce number of validations ctrl.$validate(); }); diff --git a/src/ng/directive/ngModel.js b/src/ng/directive/ngModel.js index 6098cd08a829..f5d3baf50111 100644 --- a/src/ng/directive/ngModel.js +++ b/src/ng/directive/ngModel.js @@ -506,7 +506,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ */ this.$validate = function() { // ignore $validate before model is initialized - if (isNumber(ctrl.$modelValue) && isNaN(ctrl.$modelValue)) { + if (isNumberNaN(ctrl.$modelValue)) { return; } @@ -676,7 +676,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ } } } - if (isNumber(ctrl.$modelValue) && isNaN(ctrl.$modelValue)) { + if (isNumberNaN(ctrl.$modelValue)) { // ctrl.$modelValue has not been touched yet... ctrl.$modelValue = ngModelGet($scope); } diff --git a/src/ng/directive/ngPluralize.js b/src/ng/directive/ngPluralize.js index 8a1b11a959e3..ace473fb9fc4 100644 --- a/src/ng/directive/ngPluralize.js +++ b/src/ng/directive/ngPluralize.js @@ -207,7 +207,7 @@ var ngPluralizeDirective = ['$locale', '$interpolate', '$log', function($locale, scope.$watch(numberExp, function ngPluralizeWatchAction(newVal) { var count = parseFloat(newVal); - var countIsNaN = isNaN(count); + var countIsNaN = isNumberNaN(count); if (!countIsNaN && !(count in whens)) { // If an explicit number rule such as 1, 2, 3... is defined, just use it. @@ -217,7 +217,7 @@ var ngPluralizeDirective = ['$locale', '$interpolate', '$log', function($locale, // If both `count` and `lastCount` are NaN, we don't need to re-register a watch. // In JS `NaN !== NaN`, so we have to exlicitly check. - if ((count !== lastCount) && !(countIsNaN && isNumber(lastCount) && isNaN(lastCount))) { + if ((count !== lastCount) && !(countIsNaN && isNumberNaN(lastCount))) { watchRemover(); var whenExpFn = whensExpFns[count]; if (isUndefined(whenExpFn)) { diff --git a/src/ng/directive/validators.js b/src/ng/directive/validators.js index ef7650f10ceb..f12afc18395e 100644 --- a/src/ng/directive/validators.js +++ b/src/ng/directive/validators.js @@ -61,7 +61,7 @@ var maxlengthDirective = function() { var maxlength = -1; attr.$observe('maxlength', function(value) { var intVal = toInt(value); - maxlength = isNaN(intVal) ? -1 : intVal; + maxlength = isNumberNaN(intVal) ? -1 : intVal; ctrl.$validate(); }); ctrl.$validators.maxlength = function(modelValue, viewValue) { diff --git a/src/ng/filter/limitTo.js b/src/ng/filter/limitTo.js index 02e227686ded..a6e94783fdbc 100644 --- a/src/ng/filter/limitTo.js +++ b/src/ng/filter/limitTo.js @@ -96,7 +96,7 @@ function limitToFilter() { } else { limit = toInt(limit); } - if (isNaN(limit)) return input; + if (isNumberNaN(limit)) return input; if (isNumber(input)) input = input.toString(); if (!isArray(input) && !isString(input)) return input; diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 71a82dcda547..1dde94a182f8 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -768,8 +768,7 @@ function $RootScopeProvider() { if ((value = watch.get(current)) !== (last = watch.last) && !(watch.eq ? equals(value, last) - : (typeof value === 'number' && typeof last === 'number' - && isNaN(value) && isNaN(last)))) { + : (isNumberNaN(value) && isNumberNaN(last)))) { dirty = true; lastDirtyWatch = watch; watch.last = watch.eq ? copy(value, null) : value;