Skip to content

A platform for community discussion. Free, open, simple.

FIX: Polyfill String.startsWith function for IE11

David Taylorb34f09f8d7f6
diff --git a/plugins/discourse-internet-explorer/public/js/ie.js b/plugins/discourse-internet-explorer/public/js/ie.js
index 160c9400fe0..4c0fbf5fd8e 100644
--- a/plugins/discourse-internet-explorer/public/js/ie.js
+++ b/plugins/discourse-internet-explorer/public/js/ie.js
@@ -321,6 +321,16 @@ if (!String.prototype.repeat) {
};
}
+// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith#Polyfill
+if (!String.prototype.startsWith) {
+ Object.defineProperty(String.prototype, "startsWith", {
+ value: function(search, rawPos) {
+ var pos = rawPos > 0 ? rawPos | 0 : 0;
+ return this.substring(pos, pos + search.length) === search;
+ }
+ });
+}
+
/*!
* Symbol-ES6 v0.1.2
* ES6 Symbol polyfill in pure ES5.