Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Mootools overrides Function.prototype.bind with a non-standard version #2473
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.
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)
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!
This comment has been minimized.
This comment has been minimized.Show comment Hide comment
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.