date-to-primitive.js 569 B

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