Should one write window.X when referring to a built-in global property X in the (desktop) browser?

So, there are dozens of built-in global properties in the (desktop) browser. For instance: - `document` - `undefined` - `parseInt` - `JSON` - `location` - `alert` - `setTimout` - etc. When referring to those properties, should one explicitly note them as global properties by prefixing their name with `window.`? So, for instance: var wrap = window.document.getElementById('wrap'); and window.setTimeout(loop, 100); and var x = window.parseInt(input.value, 10); I think there are three answers to this question: 1. Yes, you should always write `window.X` when referring to global properties. 2. No, you don't have to write `window.X`. Just `X` is fine. 3. It depends on the property. For some properties, use `window.X`, for some other properties use `X`. (If this is your answer, please elaborate.) So, which is it?

以上就是Should one write window.X when referring to a built-in global property X in the (desktop) browser?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏