date-to-primitive.js 519 B

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