At the core of the BOM is the window object, which represents an instance of the browser. The window object serves a dual purpose in browsers, acting as the JavaScript interface to the browser window and the ECMAScript Global object. This means that every object, variable, and function defined in a web page uses windows as its Global object and has access to methods like parseInt().

The Global Scope

  Since the window object doubles as the ECMAScript Global object, all variables and functions declared globally become properties and methods of the window object. Consider this example:

 var age = 29;
function sayAge(){
alert(this.age);
} alert(window.age);
sayAge();
window.sayAge();

  Despite global variables becoming properties of the window object, there is a slight difference between defining a global variable and defining a property directly on window: global variables cannot be removed using the delete operator, while properties defined on window can. For example:

 var age = 29;
window.color = "red"; // throws an error in IE < 9, returns false in all other browsers
delete window.age; // throws an error in IE < 9, returns true in all other browsers
delete window.color; alert(window.age); //
alert(window.color); // undefined

  Properties of window that were added via var statements have their [[Configurable]] attribute set to false and so may not be removed via the delete operator.

  Another thing to keep in mind: attempting to access an undeclared variable throws an error, but it is possible to check for the existence of a potentially undeclared variable by looking on the window object. For example:

 // this throws an error because oldValue is undeclared
var newValue = oldValue; // this doesn't throw an error, because it's a property lookup
// newValue is set to undefined
var newValue = window.oldValue;

  Keeping this in mind, there are many objects in JavaScript that are considered to be global, such as location and navigator(both discussed later in the chapter), but are actually properties of the window object.

The window object的更多相关文章

  1. js中的window.open返回object的错误

    系统中用javascript中的window.open后,页面返回了一个[object].因为系统的原因,必需使用href="javascript:window.open()"这样 ...

  2. 解决window.opener.obj instanceof Object会输出false的问题

    在a.html页面中: window.obj = {name: "jinbang"} 在a.html页面中打开新窗口b.html页面: console.log(window.ope ...

  3. window.open和window.location.href的几种用法

    windows.open("URL","窗口名称","窗口外观设定"); <A href="javascript:windo ...

  4. JavaScript Window 对象

    < JavaScript Window Object > && < IE check > JavaScript Window Object Window.loa ...

  5. window.navigate 与 window.location.href 的使用区别介绍

    window.navigate(sURL)方法是针对IE的,不适用于FF,在HTML DOM Window Object中,根本没有列出window.navigate方法. 要在javascript中 ...

  6. window.open()&&window.showmodaldialog()

    open 打开一个新窗口,并装载URL指定的文档,或装载一个空白文档,如果没提供URL的话. 适用于 窗口 语法 window = object.open([URL[,name[,features[, ...

  7. window.location 小结)

    其实在网上都能找到,我只是总结一下,方便自己查找使用 示例URL:http://b.a.com:88/index.php?name=kang&when=2011#first 属性     含义 ...

  8. document.onclick vs window.onclick

    The JavaScript Window object is the highest level JavaScript object which corresponds to the web bro ...

  9. android应用开发之Window,View和WindowManager .

    ViewManager  vm = a.getWindowManager(); vm.add(view,l); window :一个抽象的窗口基类,控制顶层窗口的外观和行为.作为顶层窗口,可控制窗口背 ...

随机推荐

  1. 【转载】Stanford CoreNLP Typed Dependencies

    总结自Stanford typed dependencies manual 原文链接:http://www.jianshu.com/p/5c461cf096c4 依存关系描述句子中词与词之间的各种语法 ...

  2. Nginx 的简介

    1. 什么是 nginx :Nginx 是高性能的 HTTP 和反向代理的服务器,处理高并发能力是十分强大的,能经受高负 载的考验,有报告表明能支持高达 50,000 个并发连接数.  2. 正向代理 ...

  3. k8spod探测

    一.pod存活性探测 pod spec为容器列表中的相应容器定义其专用的探针即可启用存活性探测,目前,k8s的容器支持存活性探测的方法包含:ExecAction.TCPSocketActon和HTTP ...

  4. centos7安装教程(U盘启动盘制作)

    Centos7 系统安装步骤. 1,准备一个8gU盘. 2.iso系统镜像文件. 3.下载UltraISO软件制作启动盘. 点击试用 选中u盘

  5. qt5---步长调节器SpinBox和QDoubleSpinBox

    #include <QSpinBox>            #include <QDoubleSpinBox> QSpinBox 用于整数的显示和输入,一般显示十进制数,也可 ...

  6. springmvc手动渲染jsp

    因为需要MockHttpServletResponse对象来得到输出的内容,要引入的包 <dependency> <groupId>org.springframework< ...

  7. 【leetcode】1244. Design A Leaderboard

    题目如下: Design a Leaderboard class, which has 3 functions: addScore(playerId, score): Update the leade ...

  8. STM32使用HAL库,使用延时卡死的问题。

    之前一直使用标准库的,现在转到HAL库来后,编写了第一个程序就遇到了问题.发现我使用库里的延时程序HAL_Delay()时,会卡死在里面. 根据程序,进入到这个延时程序后 ,发现HAL_GetTick ...

  9. CF 25 E 三个字符串 KMP模板

    Test Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status ...

  10. TTTTTTTTTTTTTTTTTTTTT POJ 3690 0与* 二维哈希 模板 +multiset

    Constellations Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5923   Accepted: 1164 De ...