Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery IE bind this

In IE I am getting this error in the console using JQuery:

SCRIPT438: Object doesn't support property or method 'bind' default.js, line 33 character 3

$.get(URL + 'dashboard/photoList/'+categoryID, (function(o) {
        // code here
}).bind(this));

Is there a work around to binding 'this'? I'm used to this from prototype.

like image 668
JREAM Avatar asked Jul 04 '11 19:07

JREAM


1 Answers

bind is only available in browsers supporting ECMAScript 5. Unlike (apparently) Prototype.js, jQuery does not extend built-in objects.

jQuery offers $.proxy [docs]:

$.get(URL + 'dashboard/photoList/'+categoryID, $.proxy(function(o) {
        // code here
},this));
like image 177
Felix Kling Avatar answered Oct 03 '22 04:10

Felix Kling