javascriptでモジュール化して欠陥を避ける
2063 ワード
//
//alert("test");
String.prototype.findx=function(){
var entity={
quot:'"',
lt:'<',
gt:'>'
};
return function(){
var temp="";
this.replace(/&([\w]+);/g,function(a,b,c){
var r=entity[b];
console.info("a: "+a+" "+"b: "+b+" "+"c: "+c);
typeof r==="string" ?r:a;
temp+=r;
});
return temp;
};
}();
console.info('<">'.findx);
console.info('<">'.findx());
/*
var username="dddaaaccc dsfsf";
console.info(username.replace(/(\w){3}/g,function(word,cc,c){
var x=1;
console.info("word: "+word+" "+"cc: "+cc+" "+"c: "+c);
return x;
}));
*/
var username="<">";
var entity1={
quot:'"',
lt:'<',
gt:'>'
};
console.info(username.replace(/&([\w]+);/g,function(word,cc,c){
var x=entity1[cc];
console.info("word: "+word+" "+"cc: "+cc+" "+"c: "+c);
return x;
}));
// java
var serialMake=function(){
var prefix="";
var seq=0;
return{
setPrefix:function(p){
prefix=p+"";
},
setSeq:function(s){
seq=s;
},
getSeq:function(){
var result=prefix+seq;
seq+=1;
return result;
}
};
};
//
//
var ser=serialMake();
ser.setPrefix("Q");
ser.setSeq(1000);
console.info(ser.getSeq()); //Q1000
console.info(ser.getSeq()); //Q1001
console.info(ser.getSeq()); //Q1002
//serialMake java ,