是否需要在窗口对象前加上 setTimeout 和 setInterval? [英] Is there a need to prepend setTimeout and setInterval with window object?

查看:56
本文介绍了是否需要在窗口对象前加上 setTimeout 和 setInterval?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Mozilla 文档中,有一些例子用 window. 写在定时器函数前面,有些没有:

In the Mozilla documentation, there are some examples written with window. in front of the timer functions and some without:

function delayedAlert() {
  timeoutID = window.setTimeout(slowAlert, 2000);
}...

setTimeout(myArray.myMethod, 1000);...

window.setInterval = function (vCallback, nDelay...

我一直在写我的代码,没有前面的 window. 到目前为止没有任何问题.我想知道是否有任何必要的情况.

I have been writing my code without window. in front without any problem so far. I want to find out if there is any situation when it would be necessary.

推荐答案

If ..

  1. 在给定名称的范围内没有其他标识符(xwindow),并且;
  2. 没有解析给定名称(xwindow)的 with 绑定,并且;
  3. 给定的名称 (x) 是全局范围 (window) 中的一个属性
  1. There is no other identifier in scope with the given name (x or window), and;
  2. There is no with binding that resolves the given name (x or window), and;
  3. The given name (x) is a property in the global scope (window)

.. 那么 window.xx 是等价的.

.. then window.x and x are equivalent.

对于标准规定的全局属性/函数(必须存在于健全的网络浏览器环境的全局范围内),我不包括window.我也注意不要隐藏这些名字.

For standards-mandated global properties/functions (which must exist in the global scope of a sane web-browser environment), I do not include window. I also take care not to shadow such names.

这篇关于是否需要在窗口对象前加上 setTimeout 和 setInterval?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆