util: improve util.isDate() function

The old implementation was fragile. i.e. node-time is an example of a user-land
module that exports an extended Date object (with a few added functions on it's
own Date object's prototype). In that case, the old check fails.
pull/22966/head
Nathan Rajlich 2011-08-30 23:13:45 -07:00 committed by Ben Noordhuis
parent 2b0a7d63a8
commit 44574bc39b
1 changed files with 2 additions and 5 deletions

View File

@ -332,11 +332,8 @@ function isRegExp(re) {
function isDate(d) { function isDate(d) {
if (d instanceof Date) return true; return d instanceof Date ||
if (typeof d !== 'object') return false; (typeof d === 'object' && Object.prototype.toString.call(d) === '[object Date]');
var properties = Date.prototype && Object.getOwnPropertyNames(Date.prototype);
var proto = d.__proto__ && Object.getOwnPropertyNames(d.__proto__);
return JSON.stringify(proto) === JSON.stringify(properties);
} }