Briz schrieb:
> I'm mostly interested in how to cleanly and reliably deal with scope 
> issues in callbacks.
I haven't read every detail of your example. Some suggestions:

- Do not extend Object.prototype. That can give you quite a lot of trouble
- Try to gather all necessary callbacks inside the plugin method 
(jQuery.fn.foo) or the constructor (jQuery.foo) and delegate to methods 
of your object inside the callbacks, while keeping the anonymous 
functions for the callbacks as small as possible
- Avoid using each() in your code, and use a small plugin instead, 
heavily reduces the need for anonymous functions inside your object's code
- Use your object function (jQuery.foo) only as a constructor, try to 
put all methods into jQuery.foo.prototype (less stuff in cunstructor -> 
better OO design)

A bit additional explanation. The code structure would look like this:

jQuery.foo = function(element) {
        // constructor code here
        var self = this;
        // access self in callbacks, eg.
        $(element).click(function(event) {
                self.handle(event);
        });
}
jQuery.foo.prototype = {
        // methods here, like handle()
}

Obviously you can't access "self" from your methods, so you have to 
design everything well enough to be able to work without "self".

Hope that helps.

-- 
Jörn Zaefferer

http://bassistance.de


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to