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

Re: [json] Re: JSON2 is futuristic code? & change request for Date handling

Expand Messages
  • Peter Michaux
    On Tue, May 20, 2008 at 12:31 PM, Douglas Crockford ... I think in this situation it could introduce bugs in other people s programs. Suppose someone had the
    Message 1 of 7 , May 20 1:38 PM
    • 0 Attachment
      On Tue, May 20, 2008 at 12:31 PM, Douglas Crockford
      <douglas@...> wrote:
      > --- In json@yahoogroups.com, "Peter Michaux" <petermichaux@...> wrote:
      >> This file modifies the built in Data.prototype object. In many
      >
      > circles modifying
      >> objects you don't own is considered a sin. I agree with that
      >> sentiment.
      >
      > I don't. Augmentation of the core objects is one of the places where
      > we can effectively repair the language. It should not be done
      > carelessly. I think this is a good use. It will likely be built into
      > the next edition of the standard.

      I think in this situation it could introduce bugs in other people's
      programs. Suppose someone had the impression that the json.js file
      only added the JSON global object and they wrote this.

      <script>
      Date.prototype.toJSON = function() {return 'boshatta';};
      </script>
      <script src="json2.js"></script>

      When the json2.js file loads it clobbers the user defined function above.

      Yes an if statement could be put around the augmentation of
      Date.prototype in json2.js but that is only a patch. Other unexpected
      behavior could occur if the application programmer is augmenting the
      Date.prototype based on some conditional that *his* code hasn't been
      augmented before.

      Since the json2.js library can be written without augmenting
      Date.prototype, I think that is the conservative choice.

      For this type of reason, I don't think that any library should augment
      built in prototypes. It always leads to some grief somewhere. If
      augmentation is done at all it should only be done at the top
      application level where the application programmer should know they
      are doing it. Even then I don't think it is a good idea.


      > In the meantime, json2.js is just a reference implementation. If you
      > don't like the way it works, you are free to modify it.

      I was hoping that since the change would be minor that the reference
      implementation could be made to appeal to a wider audience. Then
      maintanence duplication is not necessary as the reference
      implementation continues to change.

      > And I think you meant Date, not Data.

      Yes.

      Peter
    • Martin Cooper
      On Mon, May 19, 2008 at 10:56 AM, Peter Michaux wrote: ... So do I. I thought this was one of the big steps forward in moving
      Message 2 of 7 , May 20 1:50 PM
      • 0 Attachment
        On Mon, May 19, 2008 at 10:56 AM, Peter Michaux <petermichaux@...>
        wrote:
        <snip/>

        >
        > This file modifies the built in Data.prototype object. I believe that
        > is the only built-in object it modifies. In many circles modifying
        > objects you don't own is considered a sin. I agree with that
        > sentiment.


        So do I. I thought this was one of the big steps forward in moving from the
        original json.js to the new and improved json2.js, where the former
        augmented several basic types and the latter avoided such augmentation
        altogether.

        http://www.json.org/json.js
        http://www.json.org/json2.js

        It seems like a step backward to regress to the point at which the newer
        code is augmenting basic types again.

        --
        Martin Cooper



        > Would it be acceptable to stop making this augmentation in
        > the json2.js file? I don't think it would change how the file works
        > much and would make the code acceptable to a wider audience. An if
        > statement in the "case: 'object'" section would work, I believe.
        >
        > ----------------
        >
        > There is a comment
        >
        > // Return the JSON object containing the stringify, parse, and quote
        > methods.
        >
        > It doesn't look like a "quote" method is a property of the JSON object.
        >
        > Thanks,
        > Peter
        >
        > ------------------------------------
        >
        > Yahoo! Groups Links
        >
        >
        >
        >


        [Non-text portions of this message have been removed]
      • Mark Joseph
        Is there some place where JSON2 is defined without an implementation (just like version 1.0). Thanks, Mark P6R, Inc On Tue, 20 May 2008 13:50:31 -0700 ... Mark
        Message 3 of 7 , May 20 4:53 PM
        • 0 Attachment
          Is there some place where JSON2 is defined without an
          implementation (just like version 1.0).

          Thanks,
          Mark
          P6R, Inc


          On Tue, 20 May 2008 13:50:31 -0700
          "Martin Cooper" <mfncooper@...> wrote:
          > On Mon, May 19, 2008 at 10:56 AM, Peter Michaux
          ><petermichaux@...>
          > wrote:
          > <snip/>
          >
          >>
          >> This file modifies the built in Data.prototype object. I
          >>believe that
          >> is the only built-in object it modifies. In many circles
          >>modifying
          >> objects you don't own is considered a sin. I agree with
          >>that
          >> sentiment.
          >
          >
          > So do I. I thought this was one of the big steps forward
          >in moving from the
          > original json.js to the new and improved json2.js, where
          >the former
          > augmented several basic types and the latter avoided
          >such augmentation
          > altogether.
          >
          > http://www.json.org/json.js
          > http://www.json.org/json2.js
          >
          > It seems like a step backward to regress to the point at
          >which the newer
          > code is augmenting basic types again.
          >
          > --
          > Martin Cooper
          >
          >
          >
          >> Would it be acceptable to stop making this augmentation
          >>in
          >> the json2.js file? I don't think it would change how the
          >>file works
          >> much and would make the code acceptable to a wider
          >>audience. An if
          >> statement in the "case: 'object'" section would work, I
          >>believe.
          >>
          >> ----------------
          >>
          >> There is a comment
          >>
          >> // Return the JSON object containing the stringify,
          >>parse, and quote
          >> methods.
          >>
          >> It doesn't look like a "quote" method is a property of
          >>the JSON object.
          >>
          >> Thanks,
          >> Peter
          >>
          >> ------------------------------------
          >>
          >> Yahoo! Groups Links
          >>
          >>
          >>
          >>
          >
          >
          > [Non-text portions of this message have been removed]
          >

          -------------------------
          Mark Joseph, Ph.D.
          President and Secretary
          P6R, Inc.
          http://www.p6r.com
          408-205-0361
          Fax: 831-476-7490
          Skype: markjoseph_sc
          IM: (Yahoo) mjoseph8888
          (AIM) mjoseph8888
        • Peter Michaux
          On Tue, May 20, 2008 at 12:31 PM, Douglas Crockford ... I think it would be difficult to argue that the language is broken in this case. It simply does not
          Message 4 of 7 , May 22 11:54 AM
          • 0 Attachment
            On Tue, May 20, 2008 at 12:31 PM, Douglas Crockford
            <douglas@...> wrote:
            > --- In json@yahoogroups.com, "Peter Michaux" <petermichaux@...> wrote:
            >> This file modifies the built in Data.prototype object. In many
            >
            > circles modifying
            >> objects you don't own is considered a sin. I agree with that
            >> sentiment.
            >
            > I don't. Augmentation of the core objects is one of the places where
            > we can effectively repair the language.

            I think it would be difficult to argue that the language is broken in
            this case. It simply does not have a particular method.

            Peter
          • Peter Michaux
            On Tue, May 20, 2008 at 12:31 PM, Douglas Crockford ... There is another weakness in the API caused by the json2.js library s dependency on augmenting
            Message 5 of 7 , Jul 28, 2008
            • 0 Attachment
              On Tue, May 20, 2008 at 12:31 PM, Douglas Crockford
              <douglas@...> wrote:
              > --- In json@yahoogroups.com, "Peter Michaux" <petermichaux@...> wrote:
              >> This file modifies the built in Data.prototype object. In many
              >
              > circles modifying
              >> objects you don't own is considered a sin. I agree with that
              >> sentiment.
              >
              > I don't. Augmentation of the core objects is one of the places where
              > we can effectively repair the language. It should not be done
              > carelessly. I think this is a good use. It will likely be built into
              > the next edition of the standard.

              There is another weakness in the API caused by the json2.js library's
              dependency on augmenting Date.prototype with the toJSON property. If
              the json2.js library is defined in one window and a child window's
              Date object is being stringified, then the child window's
              Date.prototype will not have the toJSON property.

              // parent -----------------------------------------

              <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
              "http://www.w3.org/TR/html4/strict.dtd">
              <html>
              <head>
              <title>Date prototype augmentation test with frames</title>
              <script type="text/javascript">
              Date.prototype.foo = function() {}
              var test = function() {
              var d = window.frames.childFrame.getDate()
              alert(d.foo); // undefined
              }
              </script>
              </head>
              <body>
              <p>parent</p>
              <p><a href="#" onclick="test();return false;">test</a></p>
              <iframe name="childFrame" src="child.html"></iframe>
              </body>
              </html>


              // child --------------------------------

              <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
              "http://www.w3.org/TR/html4/strict.dtd">
              <html>
              <head>
              <title>Page Title</title>
              <script type="text/javascript">
              var getDate = function() {
              return new Date();
              };
              </script>
              </head>
              <body>
              <p>inset</p>
              </body>
              </html>


              Peter
            Your message has been successfully submitted and would be delivered to recipients shortly.