Loading ...
Sorry, an error occurred while loading the content.

SV: [json] new Date(NaN)

Expand Messages
  • Jakob Kruse
    Just to clarify this… ”new Date()” normally produces a perfectly ok Date object representing the current date and time. Does your change to ES5 mean that
    Message 1 of 2 , Jun 18 10:44 AM
    • 0 Attachment
      Just to clarify this…

      ”new Date()” normally produces a perfectly ok Date object representing the current date and time. Does your change to ES5 mean that “JSON.stringify([ <any date object> ])” will produce “[null]”? And if not, why should it refuse to stringify the current date and time in this manner when other dates and times give meaningful results?

      /Jakob


      Fra: json@yahoogroups.com [mailto:json@yahoogroups.com] På vegne af Douglas Crockford
      Sendt: 18. juni 2009 18:43
      Til: json@yahoogroups.com
      Emne: [json] new Date(NaN)

      I had always assumed that new Date(NaN) in JavaScript would throw an exception. I found out today that produces a toxic date object, and that different implementations of JSON.stringify([new Date()]) do different things.

      json2.js
      ["NaN-NaN-NaNTNaN:NaN:NaNZ"]

      IE8
      ["--T::Z"]

      FireFox
      ["Invalid Date"]

      We will be correcting the ES5 standard to emit null in this case.
      The 2009-06-18 edition of json2.js contains the change.

      [null]

      Thanks to Joel Finch for the heads up.

      [Non-text portions of this message have been removed]
    • Douglas Crockford
      ... I meant exactly what I said. This only concerns new Date(NaN).
      Message 2 of 2 , Jun 18 10:52 AM
      • 0 Attachment
        --- In json@yahoogroups.com, "Jakob Kruse" <kruse@...> wrote:
        > "new Date()" normally produces a perfectly ok Date object representing the current date and time. Does your change to ES5 mean that "JSON.stringify([ <any date object> ])" will produce "[null]"? And if not, why should it refuse to stringify the current date and time in this manner when other dates and times give meaningful results?


        I meant exactly what I said. This only concerns new Date(NaN).
      Your message has been successfully submitted and would be delivered to recipients shortly.