button.onclick = $.proxy(function() {
//这里可以直接用this访问外围对象
}, this);

解决方案 »

  1.   


    if(Function.prototype.bind){
    Function.prototype.bind = function(context){
    if(arguments.length<2&&context==void 0){
    return this;
    }
    var _method=this,args=[].slice.call(arguments,1);
    return function(){
    return _method.apply(context,args.concat.apply(args,arguments));
    }
    }
    }
    button.onclick = function(){
    //this === "外围变量";
    }.bind("外围变量");
      

  2.   


    if(!Function.prototype.bind){
    Function.prototype.bind = function(context){
    if(arguments.length<2&&context==void 0){
    return this;
    }
    var _method=this,args=[].slice.call(arguments,1);
    return function(){
    return _method.apply(context,args.concat.apply(args,arguments));
    }
    }
    }
    button.onclick = function(){
    //this === "外围变量";
    }.bind("外围变量");
      

  3.   

    答的好。
    这样不行吗?
    button.onclick = function() {
    //这里想要调用外围对象的某个方法
      //此时this指代的是button对象,而不是外围对象。这里不能使用this.方法名
    }
     (function (me) {
          me.方法//这个指的就是外面的this吧?
        })(this);