Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Result of expression near '...}.bind(this))...' [undefined] is not a function

I am getting a Safari only error: TypeError: Result of expression near '...}.bind(this))...' [undefined] is not a function.

These are lines 88-92:

$(this.options.work).each(function(i, item) {
  tmpItem = new GridItem(item);
  tmpItem.getBody().appendTo($("#" + this.gridId));
  this.gridItems.push(tmpItem);
}.bind(this));

Any ideas what is causing this?

like image 395
Dustin Avatar asked Dec 22 '22 07:12

Dustin


1 Answers

Older versions of Safari don't support bind. If you try this (http://jsfiddle.net/ambiguous/dKbFh/):

console.log(typeof Function.prototype.bind == 'function');

you'll get false in older Safaris but true in the latest Firefox and Chrome. I'm not sure about Opera or IE but there is a compatibility list (which may or may not be accurate):

http://kangax.github.com/es5-compat-table/

You can try to patch your own version in with something like this:

Function.prototype.bind = function (bind) {
    var self = this;
    return function () {
        var args = Array.prototype.slice.call(arguments);
        return self.apply(bind || null, args);
    };
};

but check if Function.prototype.bind is there first.

like image 199
mu is too short Avatar answered Dec 24 '22 00:12

mu is too short