How can I keep the context of 'this' in jquery

前端 未结 6 1925
情话喂你
情话喂你 2020-12-31 20:11

I have something like this:

var Something = function(){
  this.render = function(){};
  $(window).resize(function(){
    this.render();
  });
}
6条回答
  •  轮回少年
    2020-12-31 20:26

    I've been doing it this way in many tight situations. It doesn't look elegant, but it never fails. Actually thats javascript closures in action.

    jrh

提交回复
热议问题