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前端其它相关文章!