Saturday, December 26, 2009

Re: [jQuery] Rebinding not working

That .live() code wouldn't work because what you've really written is:

       var temp = exp_iphone_get_trans();
       $('#transactions ul li a').live('click tap', temp);

Now you can probably see what the problem is with that. By adding the () after the function name, you are *calling* the function immediately and then passing its *return value* to the .live() method.

Note that your other code with .bind() doesn't have the extra () after the callback funciton name.

Here's a subtle thing, but I find it very helpful to put whitespace inside the parentheses of a function call. So this line of code:

       $('#transactions ul li a').live('click tap', exp_iphone_get_trans());

I would have written as:

       $('#transactions ul li a').live( 'click tap', exp_iphone_get_trans() );

Now it's become a little easier to see those extra () after the callback function name.

Another subtle thing, but I also find it helpful to avoid names_with_underscores and instead use camelCaseNames. Why? The underscore is a punctuation mark, and in a language with so much significant punctuation, these extra punctuation marks detract from the meaningful ones. So I might write the code like:

       $('#transactions ul li a').live( 'click tap', iPhoneGetTrans() );

Now things are "stuck together" visually for me in a way that better highlights the significant punctuation. For me at least this helps that extra () after the iPhoneGetTrans name stand out, so hopefully I would catch on and correct it to:

       $('#transactions ul li a').live( 'click tap', iPhoneGetTrans );

-Mike

On Sat, Dec 26, 2009 at 1:29 PM, mrtoner <don@donmorris.com> wrote:

Using jQ 1.3.2; I also tried

       $('#transactions ul li a').live('click tap', exp_iphone_get_trans());

to no avail. Any suggestions?

No comments: