I need the trim() function in IE8 but it's only available in IE9. How do I add it myself to IE8? I've heard of shimming or something similar but how does it work?
I'm currently writing this code:
var trim = String.trim || function (str) {
    return x.replace(/^\s+|\s+$/gm,'');
}
But then I need to replace all str_variable.trim() with trim(str_variable). How else can I write trim function and add it to String?