Skip to content

Commit

Permalink
Add polyfill for Array.prototype.indexOf()
Browse files Browse the repository at this point in the history
  • Loading branch information
Infocatcher committed Oct 15, 2016
1 parent 15ecc0e commit 82bbbbf
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions jsBeautifier.js
Expand Up @@ -175,6 +175,21 @@ function getRawArgs() {

var window = {}; // Fake window object to import things from beautify.js

if(!Array.prototype.indexOf) {
// Based on code from https://gist.github.com/revolunet/1908355
Array.prototype.indexOf = function(elt /*, from*/) {
var len = this.length >>> 0;
var from = +(arguments[1]) || 0;
from = from < 0 ? Math.ceil(from) : Math.floor(from);
if(from < 0)
from += len;
for(; from < len; ++from)
if(from in this && this[from] === elt)
return from;
return -1;
};
}

//== index.html
// When update this section, replace all document.getElementById() calls with above options
// And leave beautify(source, syntax) and runTests() entry points
Expand Down

0 comments on commit 82bbbbf

Please sign in to comment.