What are the performance repercussions of adding functions to the String class in JavaScript and Node.js?

Viewed 407

What are the repercussions of adding functions to the String class in JavaScript? Is this a bad idea? E.g.,

// String functions
String.prototype.startsWith = function(string) {
    return (this.indexOf(string) === 0);
}
String.prototype.empty = function() {
    //console.log($.trim(this.valueOf()));
    if($.trim(this.valueOf()) == '') {
        return true;
    }
    else {
        return false;
    }
}
5 Answers
Related