Git Product home page Git Product logo

Comments (7)

petermichaux avatar petermichaux commented on May 22, 2024

json2.js Date.prototoype.toJSON is also not generic. If json2.js is updated to handle extended dates correctly but not to be generic then the following check would fix things.

if (!Date.prototype.toJSON ||
    // does Date.prototype.toJSON not do extended years properly?
    ((new Date(-62198755200000)).toJSON().indexOf('-000001') === -1) ||
    // is Date.prototype.toJSON non-generic?
    (function() {
        var str = 'abc';
        try {
            return Date.prototype.toJSON.call({toISOString:function(){return str;}}) !== str;
        }
        catch (err) {
            return true;
        }
    }())) {

from es5-shim.

kriskowal avatar kriskowal commented on May 22, 2024

Thanks, @petermichaux. Good to cross paths again!

from es5-shim.

petermichaux avatar petermichaux commented on May 22, 2024

I admit the above feature test is ugly.

A workaround that could be documented in the README?...

<script src="json2.js" type="text/javascript"></script>
<script type="text/javascript">
    delete Date.prototype.toJSON
</script>
<script src="es5-shim.js" type="text/javascript"></script>

from es5-shim.

petermichaux avatar petermichaux commented on May 22, 2024

By the way, Crockford closed my tickets about improving the Date.prototype.toJSON in his json2.js.

from es5-shim.

bryanforbes avatar bryanforbes commented on May 22, 2024

What about something like this?

if (!Date.prototype.toJSON ||
    // does Date.prototype.toJSON not do extended years properly?
    !~((new Date(-62198755200000)).toJSON().indexOf('-000001')) ||
    // is Date.prototype.toJSON non-generic?
    ~(function() {
        try {
            return Date.prototype.toJSON.call({toISOString:function(){return -1;}});
        } catch (err) {
            return true;
        }
    }())) {

from es5-shim.

jdalton avatar jdalton commented on May 22, 2024

Relevant:
douglascrockford/JSON-js#27
douglascrockford/JSON-js#25

from es5-shim.

jdalton avatar jdalton commented on May 22, 2024

Additional json2.js issues:
douglascrockford/JSON-js#28

from es5-shim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.