简体   繁体   English

移动Safari不接受与此绑定的setTimeout函数

[英]Mobile Safari not accepting setTimeout function binding to this

I have a javascript object (that is instantiated several times) that contains setTimeout functions. 我有一个包含setTimeout函数的javascript对象(实例化了几次)。 The function is similar to this: 功能类似于:

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

This works fine on all browsers except for Mobile Safari. 在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 . 在对发生的情况进行测试期间,错误是在setTimeout中的函数声明末尾添加.bind(this)的结果。 Although it works when I remove the .bind(this) in Safari, it stops working on other browsers... Does anyone how I could fix this? 尽管当我在Safari中删除.bind(this)时它可以工作,但它在其他浏览器上停止工作...有人可以解决此问题吗?

Apparently no versions of mobile Safari support function.bind . 显然, 没有任何版本的移动Safari支持function.bind MDN does provide a polyfill for it though. MDN确实为此提供了一个polyfill

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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