JavaScript 预定义变量“名称" [英] JavaScript predefined variable "name"

查看:30
本文介绍了JavaScript 预定义变量“名称"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 JavaScript,刚刚发现名为 name 的变量实际上是预定义的,位于全局上下文中.

I am learning JavaScript and just discovered that variable named name, actually is predefined, sitting in global context.

我创建了新的、完全清晰的 html 文件(甚至没有在其中写入任何 html).我也在 chrome、opera 和 firefox 中测试过,同样...

I created new, completely clear html file (have not even written any html in it). Also I tested it in chrome, opera and firefox, same...

我想知道为什么会超出我的好奇心,当该变量被分配给值 "string" 时,它本身甚至没有触及它.为什么会在那里?它在做什么?

I wonder why is that, beyond my curiosity, there was case when that variable was assigned to value "string", by itself, have not even touched it. Why is that there? what is it doing?

推荐答案

Window.name 是全局对象 window 的预定义属性之一.

因为 Stephan Bijzitter 想要一个更详细的答案,所以在这里.

Since Stephan Bijzitter wants an answer with more details, here it is.

Section 7.3.1 声明 window.name 是全局对象 window 的属性,它返回窗口的名称和可以设置,更改名称.

Section 7.3.1 of the current living HTML standards states that window.name is a property of the global object window that returns the name of the window and can be set, to change the name.

Window 对象的 name 属性必须在获取时返回浏览上下文的当前名称;并在设置时,将浏览上下文的名称设置为新值.

The name attribute of the Window object must, on getting, return the current name of the browsing context; and, on setting, set the name of the browsing context to the new value.

当浏览上下文导航到另一个来源时,名称会重置.

The name gets reset when the browsing context is navigated to another origin.

这篇关于JavaScript 预定义变量“名称"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆