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

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

Expand Messages
  • Martin Cooper
    Nov 13, 2006
    • 0 Attachment
      On 11/13/06, Stephen M. McKamey <jsonml@...> wrote:
      >
      > --- In json@yahoogroups.com, Tom Metro <tmetro+json@...> wrote:
      > >
      > > Peter Michaux wrote:
      > > > By extending the Object.prototype with the new property
      > toJSONString I
      > > > can no longer use for-in loops in my JavaScript.
      > >
      > > As another poster mentioned, using hasOwnProperty(), is the way to
      > make
      > > the intended behavior work. My understanding is that hasOwnProperty()
      > > isn't widely supported yet.
      >
      > A little late to the conversation but... another alternative could be
      > to use the typeof operator (assuming one was iterating over data):
      >
      > for(k in obj)
      > if("function"!=typeof obj[k])
      > foo(k);


      Sure - if the for loop is in your own code, and not some other package that
      you're just trying to make use of.

      This issue really needs to be fixed in the JSON code, since there's no way
      you can rely on it being fixed in all the other code out there that you
      might want to use.

      --
      Martin Cooper


      Thanks,
      > smm
      >
      >
      >
      >
      >
      > Yahoo! Groups Links
      >
      >
      >
      >
      >


      [Non-text portions of this message have been removed]
    • Show all 10 messages in this topic