>> $(...).onclick().toggle().end(); This will be cool John... I have so many one-liner anonymous functions that i can get rid of then... When can we expect it.?
-GTG On 8/17/07, John Resig <[EMAIL PROTECTED]> wrote: > > > I've thought of this, as well. I also wanted to add a hook to allow: > > $(...).click(".toggle()") > > However, I'm currently leaning away from it (embedding code in strings > is messy) in favor of another solution that I'm working on: > > $(...).onclick().toggle().end(); > > Removing the need for anonymous functions entirely. > > --John > > On 8/17/07, 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. > > > > I think it would be great to be able to pass a string to these > > functions and have it internally turned into a function. > > > > For example, instead of this: > > $('#test').click(function() { alert('test'); }); > > > > I want to do this: > > $('#test').click("alert('test');"); > > > > 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); > > }; > > > > 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. > > > > Matt Kruse > > > > >