dianping/cat · error · TypeError

Function.prototype.bind - what is trying to be bound is not

Error message

Function.prototype.bind - what is trying to be bound is not callable

What it means

html5shiv ships the MDN Function.prototype.bind polyfill for old IE. Per the (now obsolete) spec draft it throws a TypeError when .bind is called on a non-function — i.e. some code did notTheFn.bind(...) or a function reference was undefined/overwritten. In a polyfilled IE8 environment this is nearly always 'undefined is not a function' manifesting through bind on an undefined variable or host object.

Source

Thrown at cat-home/src/main/webapp/assets/js/uncompressed/html5shiv.js:332

  /*--------------------------------------------------------------------------*/

  // expose html5
  window.html5 = html5;

  // shiv the document
  shivDocument(document);

}(this, document));



// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Compatibility
// IE function.bind polyfill
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 = Array.prototype.slice.call(arguments, 1), 
        fToBind = this, 
        fNOP = function () {},
        fBound = function () {
          return fToBind.apply(this instanceof fNOP && oThis
                                 ? this
                                 : oThis,
                               aArgs.concat(Array.prototype.slice.call(arguments)));
        };

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

    return fBound;
  };
}

View on GitHub (pinned to e815e74d4c)

Solutions

  1. Inspect the stack to find which variable .bind was called on, then ensure it is defined before that code runs (script order / 404s).
  2. Guard optional callbacks: if (cb && typeof cb === 'function') cb = cb.bind(ctx);
  3. Add typeof checks before binding host objects in IE-specific code paths.

Example fix

// before
var handler = window.MyWidget.onEvent.bind(ctx); // MyWidget failed to load

// after
if (window.MyWidget && typeof MyWidget.onEvent === 'function') {
  var handler = MyWidget.onEvent.bind(ctx);
}
Defensive patterns

Strategy: type-guard

Validate before calling

function bindSafe(fn, ctx) {
  return (typeof fn === 'function') ? fn.bind(ctx) : null;
}
var handler = bindSafe(window.MyWidget && MyWidget.onEvent, ctx);

Type guard

function isCallable(v) { return typeof v === 'function'; }

Prevention

When it happens

Trigger: someVar.bind(...) where someVar is undefined because the defining script failed to load or ran later; binding a non-function property (obj.method missing); feature-detection code doing X.bind on IE8 host objects that report typeof 'object'.

Common situations: Legacy IE support pages where a plugin script 404'd leaving globals undefined; third-party widgets calling .bind on optional callbacks; event handler maps referencing renamed functions.

Related errors


AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14). Data as JSON: /api/errors/f9b23623c557899e. Report an issue: GitHub.