[jQuery] jQuery and OOP

[jQuery] jQuery and OOP

Yes it would be nice, but it does not work :(. The second argument of the click() is not passed to the count method.
-----Original Message-----
From: discuss-bounces@jquery.com [mailto:discuss-bounces@jquery.com] On Behalf Of Blair Mitchelmore
Sent: Tuesday, October 24, 2006 11:58 PM
To: jQuery Discussion.
Subject: Re: [jQuery] jQuery and OOP
A technique you might find slightly less ugly is passing 'this' as an
argument when you bind the event. If I recall correctly, jQuery has the
ability to pass an arbitrary number of additional arguments as an
additional argument array to the event bind function.
function Counter() {
$('#btnCounter').click(this.count,[this]);
this.button = $('#btnCounter');
this.nr = 0;
}
In the count method I set the incremented value of the counter to the text of the button.
Counter.prototype = {
count: function(e,self) {
self.button.attr('value', self.nr++);
}
}
--
blair
Kolman NĂ¡ndor