标签:[1] fun == lse pre return === color style
var str="adada"; console.log(str.substr(-1,2)); String.prototype.substr=function(){ var tem=""; if(arguments.length===0) return this.split("").join(""); if(arguments[0]>=this.length) return tem; if(arguments.length===1&&arguments[0]<this.length){ arguments[0]=(this.length+arguments[0])%this.length; for(var i=arguments[0];i<this.length;i+=1){ tem+=this[i]; } return tem; } if(arguments.length===2){ if(arguments[1]<=0) return tem; else{ arguments[0]=(arguments[0]+this.length)%this.length; var end=arguments[0]+arguments[1]>this.length?this.length:arguments[0]+arguments[1]; for(var i=arguments[0];i<end;i+=1){ tem+=this[i]; } return tem; } } } console.log(str.substr(-1,2))
标签:[1] fun == lse pre return === color style
原文地址:https://www.cnblogs.com/me-data/p/9860526.html