1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:48:10 +00:00

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
This commit is contained in:
Jack Karamanian 2020-05-30 01:40:49 -05:00 committed by Andreas Kling
parent 4a49c8412c
commit d4e97b17ab
2 changed files with 2 additions and 2 deletions

View file

@ -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 };

View file

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