var $ = function(id){
   return typeof id == "string" ? getElementById(id):id;   
   }
    
    var Class ={
     create:function(){
     return function(){
    
     this.ini.call(this,arguments);
     }
     }
    }
    var alpha = Class.create();
    alpha.prototype = {
    
     ini:function(id)
     {
     this.id = $(id);
     }
     ,
     hight:function(){
     alert(typeof this.id.attributes);
     }
     ,
     low:function()
     {
     alert(typeof this.id.attributes);
     }
    }
    var bb = new alpha("image");
    bb.low();为什么 alert(typeof this.id.attributes); 结果是undefined 
而如果我alert(this.id) 接过是object Object
还有我想问下ini:function(id)
     {
     this.id = $(id);
     }
这里面的this.id是属于ini这个函数对象呢?还是属于alpha这个函数对象。因为ini这个函数是在prototype这个原型链上面··

解决方案 »

  1.   

     ╮(╯▽╰)╭...很痛苦啊.真想有位javascript绝世高手打通我的经脉,让我霍然开朗啊。··
            
            this,this,this
      

  2.   

       <script language="javascript">
       var $ = function(id){
                  return typeof id == "string" ? document.getElementById(id):id;   //第一处
              }
            
            var Class ={
                create:function(){
                    return function(){
                        
                        this.ini.apply(this,arguments);//第二处
                    }
                }
            }
            var alpha = Class.create();
            alpha.prototype = {
                
                ini:function(id)
                {
                    this.id = $(id);
                }
                ,
                hight:function(){
                    alert(typeof this.id.attributes);
                }
                ,
                low:function()
                {
                    alert(typeof this.id.attributes);
                }
            }
            var bb = new alpha("image");
            bb.low();
    </script>