JavaScriptはメモしやすいです.


先日<JavaScript権威の手引き>を見ましたが、手書きでひっくり返しました.メモですよね.
function funLoad() {
	var str = "69 66 20 79 6F 75 20 63 61 6E 20 72 65 61 64 20 74 65 69 73 20 77 65 20 77 61 6E 74 20 79 6F 75";
	str = str.replace(/ /g, "");
	var result = ""
	for (var i = (str.substr(0, 2) == "0x") ? 2 : 0; i < str.length; i += 2) {
		result+=(String.fromCharCode(parseInt(str.substr(i, 2), 16)));
	}
	alert(result);
}
//cook    
function usrCookie(){
	var useDate = new Date();
	useDate.setMonth(useDate.getMonth() + 1);
	document.cookie = "testCookie="+ escape("    ")+";expires="+useDate.toGMTString()+";path=/";//espires     ,domain       
	document.cookie = "testCookie1="+ escape("   very good!")+";expires="+useDate.toGMTString();//escape       
	alert(unescape(document.cookie));//unescape    escape  
}
//replace 
function usrReplace(){
	var quote = /"([^*]*)"/g;
	alert("go\" you \"od".replace(quote,"\@$1\@"));//  $1        ()  
}
//     
function usrArray(){
	var temp = null;//javaScript       ,      for     
	var array = [1,2,"hello"];
	array.length = 10;//    length   ,          
	alert("array lenght "+ array.length);//      
	array[20]="world";//20    
	alert("array lenght "+ array.length);//              
	array["good"]="good";//  good         
	for(temp in array){
		alert(array[temp]);
	}
	array.length = 2;//       (  good    ,     )
	for(temp in array){
		alert("second "+array[temp]);
	}
}
//constructor         
function usrObjType(){
	var obj = new Date();
	if(typeof obj == "object" && obj.constructor == Date){//typeof   constructor    
		alert("this Date Object!");
	}
}
//    
function userObjFun(){
	function Obj(){};
	Obj.prototype.goString =function(){alert("goString!")};//      
	Obj.disString=function(){alert("disString");}//     
	Obj.disString();//     
	new Obj().goString();//      
}
//"  "  
function userObj(){
	var Alert1 = function(){alert("zx");}
	var Obj = function(){}
	Obj.prototype.tempVal = Alert1;//     prototype   ,      Obj  
	var newObj = new Obj(); 
	Alert1.display=function(){alert("display")}
	Obj.name ="good";//       Obj,   prototype
	newObj.tempVal.display();//protptype       ,     ,    
	alert(Obj.name);
}
//    
function userObjAttr(){
	var obj = new Object();
	obj.name = "good";
	obj.sex = " ";
	for(var temp in obj){
		alert("ojb."+temp + " : " + obj[temp]);//for      
		if(temp == "sex"){
			delete obj[temp];//delete     (delete obj.sex;)
		}
	}
	for(var temp in obj){
		alert("Second ojb."+temp + " : " + obj[temp]);//for      
	}
}
//arguments   
function useArgu(x,y,z){//           
	alert("argument[1]:"+arguments[1]);//arguments     ,       
	if(arguments.length > 2){
		arguments.callee(arguments[0],arguments[1]);//callee         
	}
}
//        
function useFun(){
	var f = function funX(count){
		alert("userFun.f.funX="+count)
		if(count > 0){
			funX(--count);//          
		}
	}
	f(2);
	alert("over---------");
	try{
		funX(2);//    ,               ,funX            
	}catch(e){
		alert("error:" + e)
	}
}

//with    (     )
function useWith(){
	with(document.getElementById("aTag")){
		alert(name);
		alert(href);
	}
}
// try     
function useTry() {
	try {
		createError();
	} finally {
		throw new Error("useTye run finally Error throw!");//    finaly   Error
		//        Error
	}
	/*
	 * finally  return try { createError(); } finally { return
	 * false;//  return   Error  false }
	 */
	/*
	 *      try{ createError(); }catch(e){ alert(e); }finally{ alert("useTye run
	 * finally."); }
	 */
}
//       
function createError() {
	throw new Error("CreateError run Error throw!");
}
//lable  break,continue     
function createBreak() {
	alert(1);
	var i = 0;
	alertBreak: //         
	for (i = 0; i < 4; i++) {
		alert(i);
		break alertBreak;//    alertBreak      
	}
	alert(4);
}