Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 26, 2011
Alexander Borges Object.isNumber() NaN support ac8b228
Showing with 5 additions and 1 deletion.
  1. +1 −1 src/prototype/lang/object.js
  2. +4 −0 test/unit/object_test.js
View
2 src/prototype/lang/object.js
@@ -537,7 +537,7 @@
* //-> false
**/
function isNumber(object) {
- return _toString.call(object) === NUMBER_CLASS;
+ return _toString.call(object) === NUMBER_CLASS && !isNaN(object);
}
/**
View
4 test/unit/object_test.js
@@ -160,13 +160,17 @@ new Test.Unit.Runner({
testObjectIsNumber: function() {
this.assert(Object.isNumber(0));
this.assert(Object.isNumber(1.0));
+ this.assert(Object.isNumber(parseInt("1",10)));
+ this.assert(Object.isNumber(parseInt("0x10")));
this.assert(Object.isNumber(new Number(0)));
this.assert(Object.isNumber(new Number(1.0)));
this.assert(!Object.isNumber(function() { }));
this.assert(!Object.isNumber({ test: function() { return 3 } }));
this.assert(!Object.isNumber("a string"));
+ this.assert(!Object.isNumber(parseInt("a string",10))); //parseInt(String) returns NaN. Javascript handles NaN as a Number type
this.assert(!Object.isNumber([]));
this.assert(!Object.isNumber({}));
+ this.assert(!Object.isNumber(NaN));
this.assert(!Object.isNumber(false));
this.assert(!Object.isNumber(undefined));
this.assert(!Object.isNumber(document), 'host objects should return false rather than throw exceptions');

No commit comments for this range

Something went wrong with that request. Please try again.