Skip to main content Skip to secondary navigation Accessibility Feedback

Function.prototype.bind and Opera Mini

Last week I discovered that a few scripts that should work in Opera Mini were not. And they weren’t just failing to work. They were passing the mustard test, so important content was getting obscured with no way to access it.

The problem turned out to be with Function.prototype.bind, a late addition to the ECMAScript 5 standard that is missing from some otherwise compatible browsers (like Opera Mini). Fortunately, there’s an easy fix.

Psst... I just launched a new guide to ditching jQuery for vanilla JS. Buy it today →

Function.prototype.bind polyfill

The fix was as easy as dropping in a polyfill, courtesy of MDN:

if (!Function.prototype.bind) {
    Function.prototype.bind = function (oThis) {
        if (typeof this !== "function") {
            // closest thing possible to the ECMAScript 5
            // internal IsCallable function
            throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");

        var aArgs =, 1);
        var fToBind = this;
        fNOP = function () {};
        fBound = function () {
            return fToBind.apply(this instanceof fNOP && oThis ? this : oThis, aArgs.concat(;

        fNOP.prototype = this.prototype;
        fBound.prototype = new fNOP();

        return fBound;

All of my scripts that use Function.prototype.bind now include the polyfill.

If you liked this article, you might also like Ditching jQuery, my new beginner's guide to vanilla JavaScript. Buy it today →
  • More articles on...
  • Code

Have any questions or comments about this post? Email me at or contact me on Twitter at @ChrisFerdinandi.

Get the Weekly Digest