[OpenLayers-Dev] Openlayers and scriptaculous autoComplete

Christopher Schmidt crschmidt at metacarta.com
Sun May 13 16:18:28 EDT 2007


On Sun, May 13, 2007 at 10:51:54PM +0300, Ehud Shabtai wrote:
> On 5/13/07, Christopher Schmidt <crschmidt at metacarta.com> wrote:
> 
> >I don't think so. Does this mean that our definition of Function.bind is
> >different from that in Prototype somehow? Looking at the code, it seems
> >like the end result of the current (Prototype 1.5.1) definition and our
> >current definition in OpenLayers should end up being the same...
> 
> I'm no javascript expert but I think that the implementation is a bit
> different and that seems to be the problem.


> Here's Prototype's implementation:
> 
> Function.prototype.bind = function() {
>  var __method = this, args = $A(arguments), object = args.shift();
>  return function() {
>    return __method.apply(object, args.concat($A(arguments)));
>  }
> }
> 
> and here's the Openlayers one:
> 
> Function.prototype.bind = function() {
>  var __method = this, args = [], object = arguments[0];
>  for (var i = 1; i < arguments.length; i++)
>    args.push(arguments[i]);
>  return function(moreargs) {
>    for (var i = 0; i < arguments.length; i++)
>      args.push(arguments[i]);
>    return __method.apply(object, args);
>  }
> };
> 
> 
> I believe that the problem is in the inner function. Prototype uses
> args.concat(arguments), which I think (?) only creates a temporary
> array for calling the function. args is not changed.
> OpenLayers uses args.push which changes args and adds new elements in it.

Ahh, okay. That's probably unintentional -- I don't see any case where
the OpenLayers code would care, cause we don't bind any functions that
would be called multiple times. I bet... ah, yeah. this is probably just
a typo in our translation from Prototype -> OL stuff, dropping $A().
That's definitely a bug that I've bumped into: I'll cook up a patch
(though if you have something that works, you can feel free to create a
ticket and patch!)


> But I wasn't sure if the Openlayers implementation
> intentionally differs from prototype?

I don't think so. I think it was a mis-translation, nothing more. We
just haven't bumped into it, because our uses of 'bind' are all
one-time-only.

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Dev mailing list