Array.prototype.forEach() in IE8

This is a way to work around the issue where a function in JavaScript (in this example forEach() in object Array) is not supported in IE8 or some other older browser.

ie8.PNG

To work around this, we can explore JavaScript’s dynamic feature of extending built in functions for in this case the object Array. We can add our own forEach() funtion on the Array object in our application.

Code:

if (typeof Array.prototype.forEach != 'function') {
    Array.prototype.forEach = function(callback){
      for (var i = 0; i < this.length; i++){
        callback.apply(this, [this[i], i, this]);
      }
    };
}
 
28
Kudos
 
28
Kudos

Now read this

Using Angular $compile to Escape Watcher Hell

This is a blog on how to handle repeating directive elements without using the ng-repeat directive when using AngularJS. We’ll keep this blog high level and assume the reader knows Angular development. Sample: <div ng-repeat='spell in... Continue →