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. AIX 下的 find 命令使用

      平常我们使用 find , -size +100M/K/G ,就可以找到相应大小的文件了. 可是 AIX 平台下,却好像不能使用,虽然执行起来不报错,但是查找出来的文件却并不是我们想要的.所以 m ...

  2. [牛客] [# 1108 E] Grid

    2019牛客国庆集训派对day3 链接:https://ac.nowcoder.com/acm/contest/1108/E来源:牛客网 题意 在一个$10 ^ 9 * 10 ^ 9$ 的方格中,每次 ...

  3. springboot jpa junit测试遇到的问题

    jpa在插入数据的时候,插入的对象变量user中不能包含变量,需要时确切的值,否则会出现sql解析报错 解析报错如下图

  4. Spring使用@AspectJ开发AOP(零配置文件)

    前言: AOP并不是Spring框架特有的.Spring只是支持AOP编程 (面向切面编程) 的框架之一. 概念: 1.切面(Aspect) 一系列Advice + Pointcut 的集合. 2.通 ...

  5. hivesql之str_to_map函数

    str_to_map(字符串参数, 分隔符1, 分隔符2) 使用两个分隔符将文本拆分为键值对. 分隔符1将文本分成K-V对,分隔符2分割每个K-V对.对于分隔符1默认分隔符是 ',',对于分隔符2默认 ...

  6. zabbix-server一键部署

    最近想写一个zabbix脚本,自己尝试几次,能够实现,但是太糙了,在github上发现一个很好,谢谢作者脚本作者:火星小刘 web:www.huoxingxiaoliu.com email:xtlyk ...

  7. 【传输管理③】Client集团间的传输(例:开发环境300→310,300→320)

    之前有提到: 每个环境可能有若干个Client(客户端/集团),且每个Client用途都不一样. 如下图所示,开发环境就有300,310和320三个Client. 假设开发人员在Client300中新 ...

  8. 将springboot jar应用打包成镜像并在docker运行成容器

    先看一下我的Dockerfile内容与服务器中的目录结构 上面 yibai-0.0.1-SNAPSHOT.jar 为springboot应用打成的jar包,Dockerfile为将应用打成镜像的配置文 ...

  9. react 中的路由 属性exact

    https://www.cnblogs.com/nailc/p/8718137.html(copy)

  10. k8s中flannel:镜像下载不了

    重新部署一套K8S集群时,由于K8S需要扁平化的网络,所以当执行下面的 root@master ~]# kubectl apply -f kube-flannel.yml 会开始下载镜像,然后去启动, ...