Search code examples
javascriptmobile-safaribindsettimeout

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?


Solution

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