Creating backup native methods so we can use them everywhere

Throughout TiddlyWiki core, we have code like this:

if (title.substr(0,operator.operand.length) === operator.operand)

I’m used to seeing it, and I understand why we do this (looking at you, Internet Explorer), but it’s not nearly as efficient or as easy-to-read as this:

if (title.startsWith(operator.operand))

What if we had a section of the boot.js file (or maybe a boot_backsupport.js file), which has code like the following:

if (String.prototype.startsWith === undefined) {
    String.prototype.startsWith = function(searchValue, start) {
        start = start || 0;
        return this.substr(start, searchValue.length) === searchValue;
    }
}

I know it’s usually considered bad form to edit the String.prototype or other native types, but we’d only be adding in something that most people already expect to be there. We could do this sort of thing with whatever methods we wanted to, and I think this would ultimately reduce the code base, because there are a lot of instances where we use our substr starts-with in the code.

Thoughts?

I think this should probably be under “Developers”.

Oops. Forgot there are people on here who use TiddlyWiki without tinkering with it.