复制代码代码如下所示:
string.prototype.endwith =功能(STR){
如果(str = = = =这空STR。长度| | | | | | str.length > this.length = = 0)
返回false;
如果(this.substring(this.length - str.length)= = str)
返回true;
其他的
返回false;
返回true;
}
string.prototype.startwith =功能(STR){
如果(str = = = =这空STR。长度| | | | | | str.length > this.length = = 0)
返回false;
如果(this.substr(0,str.length)= str)
返回true;
其他的
返回false;
返回true;
}
(string.prototype.trim =功能){
返回(this.replace /(^ *)|( * $)/ g,);
}
(string.prototype.ltrim =功能){
返回this.replace( /(^ *)/ g,);
}
(string.prototype.rtrim =功能){
返回this.replace( /( * $)/ g,);
}
string.format =功能(STR){
var i = 1,=参数args;
var str =参数{ 0 };
var;
返回str.replace(RE,函数(){ return args {我+ } });
};
无功json2string =功能(obj){
var t = typeof(obj);
如果(t!=对象| | { obj = = = null)
数据类型简单
如果(T = =字符串)obj = +对象+;
返回的字符串(obj);
}
{其他
数组或对象 / /递归
VaR N,V,JSON = {},ARR(obj = obj.constructor = =阵);
(N为OBJ){
V = obj { };t = typeof(V);
如果(t = =);
否则,如果为对象!= null)
V = json2string(V);
Json.push((ARR ,+ N +)+字符串(V));
}
返回(ARR{:{{)+字符串(JSON)+(ARR });
}
};