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 it would be difficult to argue that the language is broken in this case. It simply does not
    Message 1 of 7 , May 22, 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.

      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 2 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.