String prototypes in JavaScript

Shows how to create a String prototypes
1
2
3
4
5
6
7
8
9
10
11
String.prototype.stripslashes = function(){ 
    return this.replace(/<.*?>/g, '');
};
 
String.prototype.htmlspecialchars = function(){ 
    var str = this.replace(/&/g, '&');
    str = str.replace(/</g, '<');
    str = str.replace(/>/g, '>');
    str = str.replace(/"/g, '"');
    return str;
};
X

Url: http://www.jonasjohn.de/snippets/javascript/string-prototypes.htm

Language: JavaScript | User: ShareMySnippets | Created: Jan 12, 2014 | Tags: javascript htmlspecialchars string prototype