Try using Array.forEach in IE8 - it does not work.
Javascript frameworks usually have two main goals:
- Provide helper functions that allow you to perform general or complex tasks such as animation, DOM search, etc.
- Provide a consistent API so you don’t have to worry about browser compatibility.
Here is item 2. If you had to check every time you want to use the "standard" function and bypass it if it does not exist, your code will be more dirty and difficult to read, for example. For comparison:
var arr = [1,2,3,4]; if(arr.forEach) { arr.forEach(function(v,i) {
from
var arr = [1,2,3,4]; angular.forEach(arr, function(value, key) {
In fact, internally, many frameworks will check if a built-in method exists and use it, and if necessary, use its own implementation.
Point 1 is also relevant here, because, for example, Array.forEach only works with arrays, while Angular.forEach through the arrays and properties of the object in the same way, therefore it provides additional functionality for the basic Javascript implementation.
source share