Fix browser compatibilities by adding some polyfills

Chrome doesn't support Array.concat so we must use the instance method.

review1108003
This commit is contained in:
Cédric Krier
2013-10-07 12:22:39 +02:00
parent 6165a6ef9b
commit 0a792903dc
2 changed files with 33 additions and 2 deletions
+2 -2
View File
@@ -1340,12 +1340,12 @@
if (this.is_leaf(domain)) {
return [domain];
} else if (domoperator === undefined) {
return [domain_type].concat(Array.concat.apply([],
return [domain_type].concat([].concat.apply([],
domain.map(function(e) {
return this.merge(e, domain_type);
}.bind(this))));
} else if (domain_type == domoperator) {
return Array.concat.apply([], domain.map(function(e) {
return [].concat.apply([], domain.map(function(e) {
return this.merge(e, domain_type);
}.bind(this)));
} else {
+31
View File
@@ -5,6 +5,37 @@ var Sao = {};
(function() {
'use strict';
// Browser compatibility: polyfill
if (!('contains' in String.prototype)) {
String.prototype.contains = function(str, startIndex) {
return -1 !== String.prototype.indexOf.call(this, str, startIndex);
};
}
if (!String.prototype.startsWith) {
Object.defineProperty(String.prototype, 'startsWith', {
enumerable: false,
configurable: false,
writable: false,
value: function(searchString, position) {
position = position || 0;
return this.indexOf(searchString, position) === position;
}
});
}
if (!String.prototype.endsWith) {
Object.defineProperty(String.prototype, 'endsWith', {
enumerable: false,
configurable: false,
writable: false,
value: function(searchString, position) {
position = position || this.length;
position = position - searchString.length;
var lastIndex = this.lastIndexOf(searchString);
return lastIndex !== -1 && lastIndex === position;
}
});
}
Sao.error = function(title, message) {
alert(title + '\n' + (message || ''));
};