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

Re: json.js breaks for-in loops

Expand Messages
  • Douglas Crockford
    JavaScript is an imperfect language. The weird interaction between augmentation of prototypes with the for..in statement is evidence of this. This defect in
    Message 1 of 10 , Nov 14, 2006
    • 0 Attachment
      JavaScript is an imperfect language. The weird interaction between
      augmentation of prototypes with the for..in statement is evidence of
      this. This defect in the language requires that for..in blocks
      explicitly filter out unwanted stuff that is dredged up from the
      prototype chain. See http://yuiblog.com/blog/2006/09/26/for-in-intrigue/

      json.js provides the same API that will be built into ECMAScript
      Fourth Edition. That means that if your program works with json.js,
      then it will work even better when the language is revised.

      Some people do not have the luxury of being forward looking. They have
      to work with bad code that does not filter for..in, or they claim the
      right to write bad code themselves. Those people should not be using
      json.js. Fortunately, JSON encoding and decoding is so easy, there
      isn't much effort required to make an implementation that works with
      bad code.

      JSON is a standard data representation. The json.js implementation is
      not the standard. It is a reference implementation. You are free to
      use it in any way that you want, or to not use it.
    Your message has been successfully submitted and would be delivered to recipients shortly.