es6.date.to-json.js 510 B

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