I cant comment on the merits of the technical aspects, but I do appreciate Matt's desire to simplify and to suggest possible alternatives. This isn't a "love-it-or-leave-it" community. We actively discuss ideas for changing the base code. I think slamming ideas is a bad practice. It might not make it into the code, but all ideas should have the benefit of the doubt that the suggestion is thoughtful.
Regarding the specific suggestion For example, instead of this: $('#test').click(function() { alert('test'); }); I want to do this: $('#test').click("alert('test');"); I used to feel uncomfortable with the function() {} part. It had alot of parens and brackets to keep track of and made me nervous. However, it does serve the purpose of reminding me that the stuff inside there is a series of steps like a normal function is. The {} helps me to think through what I am asking jQuery to do. Something like: $('#test').click( function() { alert('test'); $(this).show(); } ); So I am mixed about it. To me, Longer seems more "understandable" but shorter is more "readable". Glen On 8/17/07, Stephan Beal <[EMAIL PROTECTED]> wrote: > > > On Aug 17, 5:51 pm, Matt Kruse <[EMAIL PROTECTED]> wrote: > > Assigning event functions like click() require an anonymous function > > for what is often a very small snippet of code. These anonymous > > functions are confusing to inexperienced javascript coders and make > > the code less readable, IMO. > > People who are unwilling to become comfortable with the language > they're working in (e.g., by using its available features, such as > anonymous functions) shouldn't be working in the language. > > > I think it would be great to be able to pass a string to these > > functions and have it internally turned into a function. > > i think this would be counter-intuitive. If i pass a string to a > function and know that it will be executed, i would expect the string > to be eval()'d, not run in a Function object, and those evaluate their > code with different scoping rules. > > > This simple code change seems to do the job: > > // Handle event binding > > jQuery.fn[o] = function(f){ > > return f ? this.bind(o, ((typeof f=="string")?Function(f):f)) : > > this.trigger(o); > > }; > > Shouldn't that be (new Function(f)) instead of (Function(f))? > > > Is it possible to change jQuery to accept a string in addition to a > > function reference where possible? Although you would lose the > > potential benefit of the closure by passing a string, you could always > > pass the function ref instead if you needed to. > > IMO this change would be far more complex that it seems because, for > example, the following no longer applies: > > if( typeof f == "function" ) { ... } > > That would have to be changed to include checks for Function: > > if( (typeof f == "function") || (f instanceof Function) ) > > and the call syntax for those are different. You can, as far as i > know, simply do f() when f is an instance of Function (i may be wrong > on that, but i don't believe JS offers any sort of operator > overloading for built-in types). > > Not only would the core be affected, but plugin authors might also > have to go back and make similar changes, for consistency. The cascade > of side-effects is enormous. > > i personally see no benefit, and several potential down-sides, to this > change. > >