Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setInterval之字符串不好用法 #9

Open
coxo opened this issue Dec 31, 2015 · 2 comments
Open

setInterval之字符串不好用法 #9

coxo opened this issue Dec 31, 2015 · 2 comments

Comments

@coxo
Copy link
Member

coxo commented Dec 31, 2015

setInterval(code,millisec)

  • code:需要调用执行的代码串
  • millisec:周期性执行或调用code之间的时间间隔。毫秒 毫秒 毫秒

这先开个头,大家也都理解。用起来也棒棒哒。

不要在定时器中使用字符串,这个是不好的习惯

注意:

  • setInterval(fun, 2000) 就可以了
  • alert会阻塞一些浏览器的进程,停了正常,小心使用

建议:
第一个参数不是字符串,本意是代码块,用引号引起来而已。
如果用引号引起来其实会转换为一个全局上下文的函数
Function("fun()").call(window)

不是一个好的用法

@VaJoy
Copy link
Member

VaJoy commented Dec 31, 2015

高性能js第七章有提到这个呢,啧啧

@coxo
Copy link
Member Author

coxo commented Jan 3, 2016

简单的记录一下。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants