Skip to content

Commit

Permalink
Added includes() polyfill.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenwalker committed Jan 14, 2020
1 parent 62dfbd4 commit 1cd14a8
Showing 1 changed file with 43 additions and 26 deletions.
69 changes: 43 additions & 26 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,36 +381,53 @@ MetacatUI.preventCompatibilityIssues = function(){
if (window.NodeList && !NodeList.prototype.forEach) {
NodeList.prototype.forEach = Array.prototype.forEach;
}
}

if (typeof Object.assign != 'function') {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
value: function assign(target, varArgs) { // .length of function is 2
'use strict';
if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}

var to = Object(target);

for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];

if (nextSource != null) { // Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
//Polyfill for Object.assign()
if (typeof Object.assign != 'function') {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
value: function assign(target, varArgs) { // .length of function is 2
'use strict';
if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}

var to = Object(target);

for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];

if (nextSource != null) { // Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true
});
}

//Polyfill for Array.includes, taken from https://stackoverflow.com/questions/31221341/ie-does-not-support-includes-method
if (!String.prototype.includes) {
String.prototype.includes = function(search, start) {
'use strict';
if (typeof start !== 'number') {
start = 0;
}

if (start + search.length > this.length) {
return false;
} else {
return this.indexOf(search, start) !== -1;
}
}
return to;
},
writable: true,
configurable: true
});
};
}
}

MetacatUI.preventCompatibilityIssues();
Expand Down

0 comments on commit 1cd14a8

Please sign in to comment.