Object.extend=function(props){ //继承父类 var prototype=Object.create(this.prototype) //初始化函数ctor var _Class=function(){ if (this.ctor) this.ctor.apply(this, arguments); } //当前类属性和方法 for(var k in props){ prototype[k]= props[k] } _Class.prototype = prototype; //类继承 _Class.extend=this.extend; //类扩展 _Class.expand = function (prop) { for (var name in prop) { prototype[name] = prop[name]; } }; return _Class } var AutoStr=Object.extend({ str:"", start:0, length:0, ctor:function(str){ var the=this this.str=str str.replace(/[(.)-(.)]/,function(m,p1,p2){ the.start=p1.charCodeAt(0) the.length=p2.charCodeAt(0)-the.start+1 }) }, eq:function(n){ return this.str.replace(/[(.)-(.)]/,String.fromCharCode(this.start+n)) } }) var d=new AutoStr("http://www.baidu.com/[a-z].html") for(var i=0;i< d.length;i++){ console.log(d.eq(i)) } //var d=new AutoStr("http://www.baidu.com/[0-9][0-2].html") //for(var i=0;i< d.length;i++){ // var v=new AutoStr(d.eq(i)) // for(var j=0;j< v.length;j++){ // console.log(v.eq(j)) // } //}
http://www.baidu.com/a.html
http://www.baidu.com/b.html
http://www.baidu.com/c.html
http://www.baidu.com/d.html
http://www.baidu.com/e.html
http://www.baidu.com/f.html
http://www.baidu.com/g.html
http://www.baidu.com/h.html
http://www.baidu.com/i.html
http://www.baidu.com/j.html
http://www.baidu.com/k.html
http://www.baidu.com/l.html
http://www.baidu.com/m.html
http://www.baidu.com/n.html
http://www.baidu.com/o.html
http://www.baidu.com/p.html
http://www.baidu.com/q.html
http://www.baidu.com/r.html
http://www.baidu.com/s.html
http://www.baidu.com/t.html
http://www.baidu.com/u.html
http://www.baidu.com/v.html
http://www.baidu.com/w.html
http://www.baidu.com/x.html
http://www.baidu.com/y.html
http://www.baidu.com/z.html