While examining the functionality of the angular.forEach
function:
Below is the code snippet for angular.forEach
:
var values = {name: 'misko', gender: 'male'};
var log = [];
angular.forEach(values, function(value, key) {
this.push(key + ': ' + value);
}, log);
expect(log).toEqual(['name: misko', 'gender: male']);
The explanation of context reads as follows:
Object to become context (this) for the iterator function.
This led me to ponder some questions:
What is the purpose of using the context parameter and when is it beneficial?
Why utilize this instead of the log variable?