这是生成 get set 方法的代码,里面的which哪位大虾给讲讲呀 
function user(properties){
    for(var i in properties){(function(which){
                var p = i;
                which["get"+p]=function(){
                   return properties[p];
           };
                which["set"+p]=function(val){
                   properties[p]=val;
           };
   })(this);
             
    }
}

解决方案 »

  1.   

    (function(a){
       //....
    })(b)
    临时定义一个函数并且马上传参调用。a是参数列表。b是传过去的值,用来代替a的
      

  2.   

    “})(this); ”this是函数下一次要传的参数
      

  3.   

    <script>
    function user(properties){ 
        for(var i in properties){
            (function(which){//which指的是下面传入的参数
                 var p = i; 
                 which["get"+p]=function(){ 
                     return properties[p]; 
                 }; 
                 which["set"+p]=function(val){ 
                     properties[p]=val; 
                 }; 
            })(this);//参数this指向该方法:user   
        } 
    }//定义对象
    var o = new Object();
    o.name = 'lihui_shine';//生成user对象
    var u = new user(o);
    alert(u.getname());
    </script>
      

  4.   

    "get"和"set"至少后面加个 _ 吧,呵呵 ^_^
      

  5.   

    是把如:{a:1,b:"x"}这样的JS对象 包装成
    {a:1,b:"x",
       geta:function(){return this.a},
       seta:function(val){this.a=val;},
       getb:function(){return this.b;},
       setb:function(val){this.b=val;}
    }
    有点像.NET或Java中的字段封装成属性
      

  6.   

    function user(properties){ 
        for(var i in properties){
    alert('i->'+i);
            (function(which){//which指的是下面传入的参数
                 var p = i; 
                 which["get"+p]=function(){ 
                     return properties[p]; 
                 }; 
                 which["set"+p]=function(val){ 
                     properties[p]=val; 
                 }; 
            })(this);//参数this指向该方法:user   
        } 
    }//定义对象
    var o = new Object();
    o.name = 'lihui_shine';
    o.meth = function(){ alert('a');};//生成user对象
    var u = new user(o);alert(u['getname']());
    u.getmeth()();学习了。蛮复杂的。