diff --git a/libraries/stdlib/js-v1/src/js/polyfills.js b/libraries/stdlib/js-v1/src/js/polyfills.js index 797894edc5a..5ca2d993663 100644 --- a/libraries/stdlib/js-v1/src/js/polyfills.js +++ b/libraries/stdlib/js-v1/src/js/polyfills.js @@ -4,21 +4,25 @@ */ if (typeof String.prototype.startsWith === "undefined") { - String.prototype.startsWith = function(searchString, position) { - position = position || 0; - return this.lastIndexOf(searchString, position) === position; - }; + Object.defineProperty(String.prototype, "startsWith", { + value: function (searchString, position) { + position = position || 0; + return this.lastIndexOf(searchString, position) === position; + } + }); } if (typeof String.prototype.endsWith === "undefined") { - String.prototype.endsWith = function(searchString, position) { - var subjectString = this.toString(); - if (position === undefined || position > subjectString.length) { - position = subjectString.length; + Object.defineProperty(String.prototype, "endsWith", { + value: function (searchString, position) { + var subjectString = this.toString(); + if (position === undefined || position > subjectString.length) { + position = subjectString.length; + } + position -= searchString.length; + var lastIndex = subjectString.indexOf(searchString, position); + return lastIndex !== -1 && lastIndex === position; } - position -= searchString.length; - var lastIndex = subjectString.indexOf(searchString, position); - return lastIndex !== -1 && lastIndex === position; - }; + }); } // ES6 Math polyfills if (typeof Math.sign === "undefined") {