Conflict with Prototype #710

Closed
colinmollenhour opened this Issue Mar 5, 2013 · 2 comments

Comments

Projects
None yet
3 participants

A legacy project uses both Prototype and Zepto and before v1.0 they played well together, but now the Zepto each method invokes Array.prototype.every which is unexpectedly a Prototype-declared method which causes an infinite recursion and call stack overflow.

Reverting Zepto's each method to use forEach with try/catch for breaking solves the problem:

each: function(callback){
  var $break = {}
  try {
    this.forEach(function(el, idx){ if (callback.call(el, idx, el) === false) throw $break })
  } catch (e) { if (e != $break) throw e }
}

Of course it would be nice if Prototype didn't override these methods, but as it is quite prolific it would be nice to make Zepto play nice with it where it is easy to do so.

ashchan commented Apr 15, 2013

Also had this problem with a site using Prototype. The infinite recursion error shows as inside each:

RangeError: Maximum call stack size exceeded.

Owner

madrobby commented Nov 24, 2013

every is a native method of ECMAScript 5th Edition (JavaScript 1.6). It's unfortunate that Prototype is overwriting it, but it's not Zepto's problem to fix this.

I suggest you monkey-patch Zepto's each method if you need to run Prototype in parallel, this should be easily achieved with a plugin.

@madrobby madrobby closed this Nov 24, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment