简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM