[OpenLayers-Dev] Openlayers and scriptaculous autoComplete

Ehud Shabtai eshabtai at gmail.com
Sun May 13 15:51:54 EDT 2007


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.

I tried to remove the inner loop in OpenLayers and used
args.concat($A(arguments)) instead. This fixes the autoComplete
problem. I assume that the correct fix is to create another local
array  and put in it both the args elements and the additional
arguments elements. But I wasn't sure if the Openlayers implementation
intentionally differs from prototype?

-- 
Ehud Shabtai
http://www.freemap.co.il/map/



More information about the Dev mailing list