Mayank
Mayank

Reputation: 5728

JavaScript resize event

I have some code like:

function Cname(id, name)
{
    ...
}

Cname.prototype.dosomething = function()
{
    ...
    //1. $(window).resize(this.handle_resize);
    //2. var self = this;
    //   $(window).resize(function(e, self){
    //       self.handle_resize(e);
    //   });
    ...
}

Cname.prototype.handle_resize= function(e)
{
}

I tried two ways to register handle_resize for window resize event as shown above, but both do not work. I understand how it works in case of global functions.

How can I make it work when a function is member of a Class?

Upvotes: 1

Views: 576

Answers (1)

rob
rob

Reputation: 10117

var self = this;
$(window).resize(function(e){
    self.handle_resize(e);
    });

Upvotes: 3

Related Questions