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. double to long

    obj to double obj to long instance of Bigdecimal public static void main(String[] args) throws Parse ...

  2. radio赋值法

    一般都会使用attr来使选中: $("#DIV的ID input[name='radio的name'][value="'+动态传的radio的value值+'"]&quo ...

  3. 阿里云-docker安装redis AND(docker基本操作命令)

    docker官网:https://hub.docker.com/search?q=redis&type=edition&offering=enterprise 1.拉取最新的redis ...

  4. python fc21~fc29踩坑记录

    最近在公司的linux fc21上安装python和anaconda, 直接mintmenu给挂掉了. 真是弱爆了. 后来,升级终于来了, 升到了fc29.好,再看看, python2.7还在, py ...

  5. 编程语言类别;运行Python程序的方式;变量和常量;Python程序的垃圾回收机制;

    目录 编程语言分类 运行Python程序的两种方式 1.交互式 变量与常量 1.变量 2.常量 3.小整数池 垃圾回收机制 编程语言分类 编程语言分为: 1.机器语言:直接用二进制的0和1和计算机(C ...

  6. SQL Server里Grouping Sets的威力【转】

    在SQL Server里,你有没有想进行跨越多个列/纬度的聚集操作,不使用SSAS许可(SQL Server分析服务).我不是说在生产里使用开发版,也不是说安装盗版SQL Server. 不可能的任务 ...

  7. react -搭建服务-2

    export const DEFAULT_TITLE = "你好"; // export const PRODUCT_SERVER_URL = "http://10.10 ...

  8. 25. ClustrixDB 使用sierra_stats导出概率分布

    ClustrixDB提供了导出概率分布(PDs)的能力,这可以与模式(DDL)一起用于调查查询的性能.通常,这个过程是在Clustrix支持请求时执行的.下面的部分概述了如何使用python脚本sie ...

  9. java文件上传下载解决方案

    javaweb上传文件 上传文件的jsp中的部分 上传文件同样可以使用form表单向后端发请求,也可以使用 ajax向后端发请求 1.通过form表单向后端发送请求 <form id=" ...

  10. 51nod 1120 机器人走方格V3

    1120 机器人走方格 V3  基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题  收藏  关注 N * N的方格,从左上到右下画一条线.一个机器人从左上走到右下,只 ...