]> git.example.dev Git - binbsis50.git/commitdiff
do not extend `String.prototype` with non-standard methods
authorLuigi Pinca <luigipinca@gmail.com>
Tue, 5 Apr 2016 16:46:12 +0000 (18:46 +0200)
committerLuigi Pinca <luigipinca@gmail.com>
Tue, 5 Apr 2016 16:57:28 +0000 (18:57 +0200)
public/js/app.js

index b5156e8c1c139f02fe7a2ec3b12bbfb558bb382f..c5c307c40d4953be4b5d8f8c89b83db4ba1abefa 100644 (file)
     , 'Yes, you guessed the title. Who is the artist?'
   ];
 
-  String.prototype.encodeEntities = function() {
-    return this.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
-  };
-
   var addCassetteBackdrop = function() {
     var html = [
       '<div id="touch-backdrop">'
     $users.empty();
   };
 
+  var encodeEntities = function(str) {
+    return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
+  };
+
   var gameOver = function(podium) {
     var html = [
       '<div class="modal-header">'
         , splits = text.split(urlregex);
 
       for (var i = 0; i < splits.length; i++) {
-        var escapedsplit = splits[i].encodeEntities();
+        var escapedsplit = encodeEntities(splits[i]);
 
         if (urlregex.test(splits[i])) {
           html += '<a target="_blank" href="' + escapedsplit + '">' +
       return html;
     }
 
-    return text.encodeEntities();
+    return encodeEntities(text);
   };
 
   // A new player has joined the game