Should .offset() make a defensive copy of the position object before passing it to a callback?

Should .offset() make a defensive copy of the position object before passing it to a callback?

I recently tried to write code like this:

$("h1").offset(function(index,curpos) {
    curpos.left += 25*index;
    return curpos;
});

It doesn't work, if I do it that way. Instead I have to write:

$("h1").offset(function(index,curpos) {
    return {left: curpos.left + 25*index, top:curpos.top};
});

jQuery either needs to make a defensive copy before calling the callback or the documentation needs to clearly state that the callback isn't allowed to modify the passed object.  I prefer the former and propose the patch below.

    David Flanagan


  1. --- jquery-1.4.2.js     2010-05-18 10:37:30.000000000 -0700
  2. +++ jquery-1.4.2.patch.js       2010-08-31 16:50:32.000000000 -0700
  3. @@ -6071,7 +6071,7 @@
  4.                         curLeft   = parseInt( jQuery.curCSS( elem, "left", true ), 10 ) || 0;
  5.  
  6.                 if ( jQuery.isFunction( options ) ) {
  7. -                       options = options.call( elem, i, curOffset );
  8. +                       options = options.call( elem, i, {left:curOffset.left,top:curOffset.top} );
  9.                 }
  10.  
  11.                 var props = {