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

541Re: [json] json.js breaks for-in loops

Expand Messages
  • Philip Tellis
    Oct 14, 2006
    • 0 Attachment
      Sometime on Oct 13, PM cobbled together some glyphs to say:

      > By extending the Object.prototype with the new property toJSONString I
      > can no longer use for-in loops in my JavaScript.

      this is a design flaw in Javascript. You need to check the
      hasOwnProperty() method when iterating in a for..in loop:

      for(k in obj)
      if(obj.hasOwnProperty(k))
      foo(k);

      --
      How often I found where I should be going only by setting out for somewhere
      else.
      -- R. Buckminster Fuller
    • Show all 10 messages in this topic