[jQuery] Re: bind method to easily create closures with this altered.

2008-02-21 Thread whylom

I'm not sure what illegal Javascript syntax is.  I just tested
Jörn's code and it runs without errors, and lets you do this:

$(thing).click(myFunc.bind(scope));

Instead of illegal, can we just call it very very risky to extend
the prototypes of native JS objects?  :)  Altering the behavior of
native prototypes can lead to new and exciting bugs in other
libraries.  These are nigh impossible to track down, since they are
caused by completely unrelated code.  This sorrow is sometimes called
action at a distance.

If you want to extend the prototype of Function, I won't tell on
you.  :)  Here is a perfectly safe alternative though:

function bind(fn, scope) {
return function() { fn.apply(scope, arguments) };
}

$(thing).click(bind(myFunc, scope));

David


On Feb 21, 1:27 am, RobG [EMAIL PROTECTED] wrote:
 On Feb 20, 9:17 pm, darki777 [EMAIL PROTECTED] wrote:

  Hi,
  is there any method to bind and create closures with this altered in
  jQuery (with chain possibility)?? Need it on various functions. I do
  not mean Events.

  Anythink like this:
  function myFunc()
  {

  }.bind(anything);

 That is illegal javascript syntax, the Function call or apply methods
 are provided for this:

   function foo(){}
   foo.call(anything);

 or perhaps:

   var boundFoo = function(){
 foo.apply(anything, arguments);
   }

 --
 Rob


[jQuery] Re: What is the easiest way to add events to dynamically added rows?

2008-02-21 Thread whylom

Wow - I asked Ariel Flesler (the developer of the Listen plugin) to
explain why one would use it instead of LiveQuery.  His response was
way more cryptic than yours.  Thanks for cutting through the haze,
Dan!

On Feb 20, 2:38 pm, Dan G. Switzer, II [EMAIL PROTECTED]
wrote:
 I am dynamically removing and adding rows using AJAX calls.

 Is it still a better idea to go with Listen?

 IMO, yes. You won't have the polling overhead like you do with LiveQuery.
 The $.Listen() plug-in only attaches itself once and then just listens for
 matching key events on it's children to see if it should trigger off a
 callback.

 IMO this is much cleaner solution and it's less likely to introduce any kind
 of memory leaks (since there's only one event ever attached.)

 -Dan


[jQuery] Safari 3 offset and empty table cells

2008-01-29 Thread whylom

I am looking for a workaround to some strange behavior I've observed
in Safari 3.  I am getting inaccurate values for the offsetTop of
table cells, but only when the cells are empty.  The width and height
are accurate.  offsetTop is even accurate for the surrounding cells,
as long as they are not empty.

I first noticed this while using jQuery's offset() function, but this
is clearly a Safari issue.  I did a great deal of research before
posting here, but I was unable to find any clues anywhere else.  Do
any of my fellow browser hackers have any ideas?