String.prototype.maxTimesC = function(){ this.str = this.toString(); this.maxTimes = 0; this.preTimes = 0; this.maxTimesC = []; while (this.str!="") { this.preTimes = this.str.split(this.str.substring(0,1)).length-1; if(this.preTimes>this.maxTimes){ //当前次数大于最大次数 this.maxTimes = this.preTimes; this.maxTimesC.length = 0; this.maxTimesC.push(this.str.substring(0,1)); }else if(this.preTimes == this.maxTimes){ //当前次数等于最大次数 this.maxTimesC.push(this.str.substring(0,1)); }else{ //当前次数小于最大次数 } this.str = this.str.split(this.str.substring(0,1)).join(""); }; if(str === ""){ alert("字符串为空"); } var result = [this.maxTimesC,this.maxTimes]; return result; };
大概功能实现 初次接触 原型 不知道怎么写才好,望多多指点