Feeds:
Posts
Comments

Posts Tagged ‘Optimization’

Steve has gotten interesting research which is making trim method and optimizing internal to JavaScript.
These are codes.

function trim11 (str) {
    str = str.replace(/^\s+/, '');
    for (var i = str.length - 1; i > 0; i--) {
        if (/\S/.test(str.charAt(i))) {
            str = str.substring(0, i + 1);
            break;
        }
    }
    return str;
}
function trim12 (str) {
    var str = str.replace(/^\s\s*/, ''),
 	ws = /\s/,
 	i = str.length;
    while (ws.test(str.charAt(--i)));
    return str.slice(0, i + 1);
}

Get more infomation from his blog

Advertisements

Read Full Post »