Просмотр исходного кода

LibJS: Use a non-arrow function to check the |this| value in the
callback for Array.prototype.{reduce,reduceRight}

Arrow functions always retain the |this| binding.

Running this code in Node:

[1, 2].reduce(() => { "use strict"; console.log(this === undefined) }

Output: false

Jack Karamanian 5 лет назад
Родитель
Сommit
d4e97b17ab

+ 1 - 1
Libraries/LibJS/Tests/Array.prototype.reduce.js

@@ -31,7 +31,7 @@ try {
         message: "Reduce of empty array with no initial value"
     });
 
-    [1, 2].reduce(() => { assert(this === undefined) });
+    [1, 2].reduce(function () { assert(this === undefined) });
 
     var callbackCalled = 0;
     var callback = () => { callbackCalled++; return true };

+ 1 - 1
Libraries/LibJS/Tests/Array.prototype.reduceRight.js

@@ -43,7 +43,7 @@ try {
     }
   );
 
-  [1, 2].reduceRight(() => {
+  [1, 2].reduceRight(function () {
     assert(this === undefined);
   });