mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 13:12:46 +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:
		
							parent
							
								
									4a49c8412c
								
							
						
					
					
						commit
						d4e97b17ab
					
				
					 2 changed files with 2 additions and 2 deletions
				
			
		|  | @ -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 }; | ||||
|  |  | |||
|  | @ -43,7 +43,7 @@ try { | |||
|     } | ||||
|   ); | ||||
| 
 | ||||
|   [1, 2].reduceRight(() => { | ||||
|   [1, 2].reduceRight(function () { | ||||
|     assert(this === undefined); | ||||
|   }); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jack Karamanian
						Jack Karamanian