// JavaScript Document
var easyUI =
{
   // easyUI base support
   fpbind : function()
   {
      // function bind to object
      if( ! Function.prototype.bind)
      {
         Function.prototype.bind = function(obj)   //obj  有什么用  没有见到何处在引用此对象啊
         {
            var owner = this, args = Array.prototype.slice.call(arguments), callobj = Array.prototype.shift.call(args);
            return function(e)
            {
               e = e || top.window.event || window.event;
               owner.apply(callobj, args.concat([e]));
            }
            ;
         }
         ;
      }
   }

解决方案 »

  1.   

    在javascript里,函数的参数有两种方法可以访问得到,一种是不言而喻的,和java,c++一样,直呼其名,上例的obj。第二种是javascript特有,通过函数体内特定的arguments对象,任何javascript函数一旦被定义,就如this一样,系统会定义一个arguments对象,该对象是一个array,也就是说,通过arguments[x]可以访问到第x-1个参数。
      

  2.   

    通过bind可以改变this指针,或者为函数绑定参数
         Function.prototype.bind = function(obj)
         {
             var owner = this, args = Array.prototype.slice.call(arguments), callobj = Array.prototype.shift.call(args);
             return function(e) {
                 e = e || top.window.event || window.event;
                 owner.apply(callobj, args.concat([e]));
             }
         }     var a = function() {
             alert(this.tagName);
         }     var b = function() {
             alert(this.tagName);
         } .bind(document.getElementById('divID'));     var c = function (cc) {
             alert(cc);
         }.bind(this, 'abcd');     a();   //显示undefined
         a.call(document.body); //显示BODY
         b();   //显示DIV
         c();   //显示abcd
      

  3.   


    // JavaScript Document
    var easyUI =
    {
      // easyUI base support
      fpbind : function()
      {
          // function bind to object
          if( ! Function.prototype.bind)
          {
            Function.prototype.bind = function(obj)  //obj,this scope,callobj就是它,args是后面跟的参数。
            {
                var owner = this, args = Array.prototype.slice.call(arguments), callobj = Array.prototype.shift.call(args);
                return function(e)
                {
                  e = e || top.window.event || window.event;
                  owner.apply(callobj, args.concat([e]));//在最终执行的函数里最后一个参数会是event对象。
                }
                ;
            }
            ;
          }
      } 
      

  4.   

    BTW,楼主在用easyUI么? ^_^
      

  5.   

    obj就是bind方法的arguments[0],
    等价于
    Array.prototype.shift.call(args)// 获取arguments中的第一个参数(arguments[0])
      

  6.   


         Function.prototype.bind = function(obj)
         {
             var owner = this, args = Array.prototype.slice.call(arguments), callobj = Array.prototype.shift.call(args);
             return function(e) {
                 e = e || top.window.event || window.event;
                 owner.apply(callobj, args.concat([e]));
             }
         }     var a = function() {
             alert(this.tagName);
         }     var b = function() {
             alert(this.tagName);
         } .bind(document.getElementById('divID'));     var c = function (cc) {
             alert(cc);
         }.bind(this, 'abcd');     a();   //显示undefined
         a.call(document.body); //显示BODY
         b();   //显示DIV
         c();   //显示abcd