Problem
This is because of arrow functions, which are a new feature in ECMAScript 2015 (also known as ES6). Since many ES6 features have not been implemented on all browsers, the allowance of new syntax varies across browsers. A few good resources are the compatibility table for ES2015 (ES6) features and the MDN documentation for arrow functions. Both outline what versions of browsers support what.
From the table we observe the following:
- Internet Explorer does not support this feature.
- Safari >=10 supports this feature.
- Chrome >=45 supports this feature.
- Firefox >= 22 supports this feature.
- Opera >= 32 supports this feature
So, arrow functions in your case did work on Chrome as they were implemented in the version of the browser you were using, but not Safari and IE because they were too old and were at a version that didn't support the feature or just don't support the feature in the first place.
Solutions
You have two options. One is easier and the other requiring a bit more work.
1) Just use function
instead. This will require some more work to achieve the arrow function's this
behavior but will be easier to use for right now. In this case, the arrow function's this
context (or lack thereof) does not matter anyways. Here's an example:
var temp = [];
$scope.mulImage = $scope.mulImage.filter(function(x, i) {
if(temp.indexOf(x.filename) < 0) {
temp.push(x.filename);
return true;
}
return false;
})
2) Use something like Babel which is a transpiler. What this means is that it transform the code to a different version. In this case, we can make it so that it transforms your ES6 code with arrow functions into regular ES5 code (the regular JavaScript we know) that is supported by all browsers. You can follow their installation instructions in the link above.