在String()构造器不存在的情况下自定义一个MyString()函数,实现如下内建String()方法和属性:
var s = new MyString(“hello”);s.length; //5s[0]; //"h"s.toString(); //"hello"s.charAt(1); //"e"s.charAt("0"); //"h"s.slice(0,-1); //"hell"s.split("e"); //["h","llo"]未实现s.reverse(); //"olleh"
var MyString=function(str) { var list = []; for (var i in str) { list[i] = str[i]; } this.list = list; this.toString=toString; this.valueOf=valueOf; this.charAt=charAt; this.concat=concat; this.slice=slice; this.split=split; this.reverse=reverse;};function toString(){ var a_str=''; for(var i=0;i0){ for(var i=m;i