topherg
topherg

Reputation: 4293

Mobile Safari not accepting setTimeout function binding to this

I have a javascript object (that is instantiated several times) that contains setTimeout functions. The function is similar to this:

setTimeout(function() {
    this.function();
}.bind(this), this.interval);

This works fine on all browsers except for Mobile Safari. During my tests on what happened, the error is the result of adding .bind(this) to the end of the function declaration in the setTimeout. Although it works when I remove the .bind(this) in Safari, it stops working on other browsers... Does anyone how I could fix this?

Upvotes: 1

Views: 1262

Answers (1)

Wonderfool
Wonderfool

Reputation: 86

Apparently no versions of mobile Safari support function.bind. MDN does provide a polyfill for it though.

Upvotes: 4

Related Questions