javascript – Problem of Polyfill implementation

I'm getting an error on IE8: the object does not support this property or this method

However, it works very well with Chrome or Mozilla

Code:
{

    var optgroup_ids = optgroupids.split (% #)[0].replace ('span', & # 39;); & # 39;
var optgroup_id = optgroup_ids.substr (0, _.lastIndexOf (optgroup_ids, & # 39;));
error = true;
mprint ("Error in optgroup condition for optgroup id:" + optgroup_id + ":" + e.message, "red");
}

I've tried adding the code snippet below to the top of the script

if (! (lastIndexOf in Array.prototype)) {

Array.prototype.lastIndexOf = function (find, i / * opt * /) {
if (i === undefined) i = this.length-1;
if I<0) i+= this.length;
        if (i>this.length-1) i = this.length-1;
for (i ++; i -> 0;) / * i ++ because the argument from is unfortunately inclusive * /
if (i in this && this[i]=== find)
returns i;
return -1;
};
} 

No chance! Need help to add polyfills.