日期:2014-05-16 浏览次数:20395 次
function Fn(){} alert(typeof Fn.prototype); //object
Fn.prototype=1; alert(typeof Fn.prototype); //number //这样就修改了prototype的值,不过意义不大
function getMap(){//初始化map_,给map_对象增加方法,使map_像个Map var map_=new Object(); //属性加个特殊字符,以区别方法名,统一加下划线_ map_.put=function(key,value){ map_[key]=value;} map_.get=function(key){ return map_[key];} map_.remove=function(key){ delete map_[key];} map_.keyset=function(){ var ret=""; for(var p in map_){ if(typeof p =='string' && p.substring(p.length-1)=="_"){ ret+=","; ret+=p; } } if(ret==""){ return ret.split(","); //empty array }else{ return ret.substring(1).split(","); } } return map_; } var map_=getMap(); map_.put('id_',"001"); map_.put('name_',"anna"); alert(map_.keyset()); //id_,name_ var keys=map_.keyset(); for(var i=0;i<keys.length;i++){ alert(map_.get(keys[i])); //001,then anna } map_.put("course_",new Array()); map_.get("course_").push("Math"); map_.get("course_").push("English"); map_.get("course_").push("Physics"); alert(map_.get("course_")); //Math,English,Physics