date-to-primitive.js 451 B

1234567891011
  1. 'use strict';
  2. var anObject = require('../internals/an-object');
  3. var toPrimitive = require('../internals/to-primitive');
  4. // `Date.prototype[@@toPrimitive](hint)` method implementation
  5. // https://tc39.es/ecma262/#sec-date.prototype-@@toprimitive
  6. module.exports = function (hint) {
  7. if (hint !== 'string' && hint !== 'number' && hint !== 'default') {
  8. throw TypeError('Incorrect hint');
  9. } return toPrimitive(anObject(this), hint !== 'number');
  10. };