3种js实现string的substring方法

  String.prototype.mysubstring=function(beginIndex,endIndex){

  var str=this,

  beginArr=[],

  endArr=[];

  if(!endIndex){

  endIndex=str.length;

  }

  for(var i=0;i

  beginArr.push(str.charAt(i));

  }

  for(var i=endIndex;i

  endArr.push(str.charAt(i));

  }

  return str.replace(beginArr.join(""),"").replace(endArr.join(""),"");

  }

  //test

  console.log("Hello world!".mysubstring(3));//"lo world!"

  console.log("Hello world!".mysubstring(3,7));//"lo w"