Skip to content

Commit e7f6af0

Browse files
committed
use a constant as a error message
1 parent b36ca26 commit e7f6af0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

packages/core-js/internals/array-reduce.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ var lengthOfArrayLike = require('../internals/length-of-array-like');
66

77
var $TypeError = TypeError;
88

9+
var REDUCE_EMPTY = 'Reduce of empty array with no initial value';
10+
911
// `Array.prototype.{ reduce, reduceRight }` methods implementation
1012
var createMethod = function (IS_RIGHT) {
1113
return function (that, callbackfn, argumentsLength, memo) {
1214
var O = toObject(that);
1315
var self = IndexedObject(O);
1416
var length = lengthOfArrayLike(O);
1517
aCallable(callbackfn);
16-
if (length === 0 && argumentsLength < 2) throw new $TypeError('Reduce of empty array with no initial value');
18+
if (length === 0 && argumentsLength < 2) throw new $TypeError(REDUCE_EMPTY);
1719
var index = IS_RIGHT ? length - 1 : 0;
1820
var i = IS_RIGHT ? -1 : 1;
1921
if (argumentsLength < 2) while (true) {
@@ -24,7 +26,7 @@ var createMethod = function (IS_RIGHT) {
2426
}
2527
index += i;
2628
if (IS_RIGHT ? index < 0 : length <= index) {
27-
throw new $TypeError('Reduce of empty array with no initial value');
29+
throw new $TypeError(REDUCE_EMPTY);
2830
}
2931
}
3032
for (;IS_RIGHT ? index >= 0 : length > index; index += i) if (index in self) {

0 commit comments

Comments
 (0)