date-to-primitive.js 489 B

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