Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Mootools overrides Function.prototype.bind with a non-standard version #2473

aviynw opened this Issue · 6 comments

3 participants


The way chrome, firefox, and IE10 all implement Function.prototype.bind is to accept first a "this" arg, followed by an arbitrary number of arguments. However mootools expects the arguments to be put into an array. Running the below the example with and without mootools on the page will illustrate the point.
var p = function(a, b){
var t = p.bind(null, 'a','b');

The second problem is that in chrome firefox and ie10 you are able to call bind multiple times such that for a function t, t.bind(null, 'a').bind(null, 'b'); t(); would execute "t" with both a and b as prepended arguments. With mootools this also doesn't work.

But for me the real problem isn't the faulty implementation but the fact that mootools overrides the native implementation. This problem came up in a library I was writing that is completely independent of mootools. Someone tried to use the library I was writing with mootools on the same page, and boom! If you want add methods to native prototypes, you should use names that aren't in the ecmascript standard, to avoid conflicting with other scripts. From your perspective I don't know how you can fix this without breaking backwards compatibility, but if you don't fix this, your library is incompatible with any script that uses function.bind without mootools.


as a workaround I'm storing the original bind function in a variable called "oldBind" before mootools loads and then I call my functions that need to use bind with restoreBindFor(myFunction)

function restoreBindFor(theFunction){
var currentBind=Function.prototype.bind;


This is only when you have 1.2 compatibility enabled (not default in 1.4.5).

@arian arian closed this

Oh I see, before I tested this I tried using it with the "compatibility" version. I thought "compatibility" meant its more compatible with arbitrary scripts, not more compatible with scripts relying on older APIs. I now tried using it with the non-compatible version and see that my problem dissapears.

An extra line on the downloads page explaining the difference between the two version would be nice, thanks!


AFAICT this is still an issue.
JSBin with mootools and @aviynw's snippet:
JSBin without mootools and @aviynw's snippet:

I'm in the same situation where I can't easily fix the hosting page and mootools' presence in the page ruins the party for my code.


@dvdplm, the outputs are the same for me... which is correct because you use the nocompat version.


@arian yes, you are right. I was (wrongly) under the impression that post v1.2 you'd have to opt-in to the broken stuff rather than the other way around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.