// start forward Michael Geary wrote: > That's not too bad, but what about .hover()? It takes two > callback functions. I guess we will have to add that context > object as the third argument. Every jQuery method would have to > have this extra argument added, documented, and tested. > [...] > I explained about closures, but he thought JavaScript programmers > were unlikely to understand them or be comfortable with them, so > he insisted that we provide context arguments very much like the > one in your example.
Well, my first language was ActionScript (Macromedia's Flash JavaScript) and also remember having participated of several discussions on the same topic. Scope chaining is very simple yet many people seem to completely misunderstand it. Let me make clear that I've got no problems with it. My only problem is having to declare an extra variable. You may say, "you don't need an extra variable", since outer contexts will be readily available due to the lexicon scoping. But in this case, understand, they will not. I'm creating a class, here's an example: function MyClass() { $(document).ready(function() { alert(this.foo); // doesn't work }); } MyClass.prototype.setFooAndDoSomething = function() { this.foo = 1; } app = new MyClass(); You see what I mean now? I need a way to preserve the current scope ("this") within an object, so I can use jQuery in a Composition-like set-up like that... As it stands the solution is having a "var self = this" variable declared in the same function context as the event callback closure is defined... but am I the only one who sees it as a bit way too messy? I guess only a few people use class-based approaches like I do, that might a possible explanation why no one has complained about it before :] Perhaps jQuery just isn't meant to be used this way, but I hope that is not the cause, since it's a really great tool set! --Jonas Galvez // end forward -- ᗷɭoℊẚᗰսɳᑯѲ⁈⁈⁈ _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/