es.number.to-precision.js 764 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. var fails = require('../internals/fails');
  4. var thisNumberValue = require('../internals/this-number-value');
  5. var nativeToPrecision = 1.0.toPrecision;
  6. var FORCED = fails(function () {
  7. // IE7-
  8. return nativeToPrecision.call(1, undefined) !== '1';
  9. }) || !fails(function () {
  10. // V8 ~ Android 4.3-
  11. nativeToPrecision.call({});
  12. });
  13. // `Number.prototype.toPrecision` method
  14. // https://tc39.github.io/ecma262/#sec-number.prototype.toprecision
  15. $({ target: 'Number', proto: true, forced: FORCED }, {
  16. toPrecision: function toPrecision(precision) {
  17. return precision === undefined
  18. ? nativeToPrecision.call(thisNumberValue(this))
  19. : nativeToPrecision.call(thisNumberValue(this), precision);
  20. }
  21. });