JS的全局变量是不是属于widow的变量?如果是,那为什么“this == document”和“this == frames”都可以打印出来?如果因为document和frames是window子对象所以可以打印,为什么同样是子对象的anchors,forms,images,navigator和screen却不能打印?
请高手指点,非常感谢!!
<html>
<head>
</head>
<body>
<script language="JavaScript" type="text/JavaScript">
if (this == document) alert("document"); //document
if (this == window) alert("window"); //window
if (this == frames) alert("frames"); //frames
//if (this == anchors) alert("anchors");
//if (this == forms) alert("forms");
//if (this == images) alert("images");
//if (this == navigator) alert("navigator");
//if (this == screen) alert("screen");
if (this === window) alert("window"); //window
</script>
</body>
</html>javascript JS this
请高手指点,非常感谢!!
<html>
<head>
</head>
<body>
<script language="JavaScript" type="text/JavaScript">
if (this == document) alert("document"); //document
if (this == window) alert("window"); //window
if (this == frames) alert("frames"); //frames
//if (this == anchors) alert("anchors");
//if (this == forms) alert("forms");
//if (this == images) alert("images");
//if (this == navigator) alert("navigator");
//if (this == screen) alert("screen");
if (this === window) alert("window"); //window
</script>
</body>
</html>javascript JS this
re:
谁告诉anchors,forms,images,navigator和screen是window的直接子对象。如果你指的是忽略继承层次。
前辈你那图我刚看明白
请不要把菜鸟的理解能力想得那么高其实那图已经回答了关键点
我觉的解释挺到位的,可以参考下。
而window与frames实际是一个引用所以不要纠结为什么this可以指向document,也可以指向window.不同内核的机制不一样.一般来说,this指向window. 而DOM里的东西严格按照标准取法来取.一般来说this会广泛的使用于类中,这里的用法网上很多.与OO思想也是基本一致的