обнаружения “недопустимая дата” дата экземпляра в javascript

я хочу сказать, разница между действительными и недействительными дата объекты в js, но не мог понять, как:

var d = new date("foo");console.log(d.tostring()); // shows 'invalid date'console.log(typeof d); // shows 'object'console.log(d instanceof date); // shows 'true'

любые идеи для написания функции?

ash recommended date.parse for parsing date strings, which gives an authoritative way to check if the date string is valid.what i would prefer, if possible, is have my api accept a date instance and to be able to check/assert whether it's valid or not. borgar's solution does that, but i need to test it across browsers. i also wonder whether there's a more elegant way.ash made me consider not having my api accept date instances at all, this would be easiest to validate.borgar suggested testing for a date instance, and then testing for the date's time value. if the date is invalid, the time value is nan. i checked with ecma-262 and this behavior is in the standard, which is exactly what i'm looking for.