You can add your methods to String.prototype, which will be available for all lines. This is how it trim()is implemented in most libraries, for example.
String.prototype.replaceSpecial = function() {
return this.replace(/l/g, 'L');
};
"hello".replaceSpecial();
, , , , . . .
function replaceSpecial(str) {
return str.replace(/l/g, 'L');
}
replaceSpecial("hello");
, .
var StringUtils = {
replaceSpecial: function(str) { .. },
..
};
StringUtils.replaceSpecial("hello");