Javascript String format(props)

Description

Javascript String format(props)


String.prototype.format = function(props){
    if(!props || props.length === 0){
        return this;
    }//from  ww  w  .  j  a v  a  2 s .c  om
    var temp = this;
    for(var i = 0; i < props.length; i++){
        var index = temp.indexOf('{');
        if(index === -1){
            break;
        }
        temp = temp.substring(0, index) + props[i] + temp.substring(index + 2);
    }
    return temp;
};



PreviousNext

Related