es6.date.to-json.js 562 B

12345678910111213141516
  1. 'use strict';
  2. var $export = require('./_export');
  3. var toObject = require('./_to-object');
  4. var toPrimitive = require('./_to-primitive');
  5. $export($export.P + $export.F * require('./_fails')(function () {
  6. return new Date(NaN).toJSON() !== null
  7. || Date.prototype.toJSON.call({ toISOString: function () { return 1; } }) !== 1;
  8. }), 'Date', {
  9. // eslint-disable-next-line no-unused-vars
  10. toJSON: function toJSON(key) {
  11. var O = toObject(this);
  12. var pv = toPrimitive(O);
  13. return typeof pv == 'number' && !isFinite(pv) ? null : O.toISOString();
  14. }
  15. });