变量称为“名称”总是在Javascript中定义? [英] Is variable called "name" always defined in Javascript?

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

问题描述

document.writeln('name=' + name); 
// name =

document.writeln('notName=' + notName); 
// ReferenceError: notName is not defined

名称是否具有某些特殊含义在JavaScript中? (在IE和FF中检查)

Does the "name" have some special meaning in javascript? (checked in IE and FF)

推荐答案


是否在Javascript中定义了名为name的变量?

Is variable called "name" always defined in Javascript?

不。但是, on browsers 有一个名为的全局名称,它是当前窗口的名称。这是浏览器上的JavaScript全局对象是Window对象这一事实的副产品。一点解释:

No. However, on browsers there's a global called name which is the name of the current window. This is a by-product of the fact that the JavaScript global object on browsers is the Window object. A bit of explanation:

在JavaScript中,全局变量实际上是称为全局对象的属性。在浏览器上,全局对象是页面的Window对象,因此它具有与之相关的各种预定义属性(因此也是全局变量) Window对象,包括但不限于:

In JavaScript, global variables are actually properties of something called the "global object." On browsers, the global object is the Window object for the page, and so it has all kinds of predefined properties (and therefore globals) on it related to it being a Window object, including but not limited to:


  • name - 当前窗口的名称

  • title - 当前窗口的标题

  • status - 状态区域内容(大多数浏览器忽略它除外)

  • document - 当前窗口中的文档

  • window - 返回全局对象的引用(例如,循环引用)

  • setTimeout - 用于安排事件发生的函数稍后

  • name - The name of the current window
  • title - The title of the current window
  • status - The status area content (except most browsers ignore it)
  • document - The document in the current window
  • window - A reference back to the global object (e.g., a circular reference)
  • setTimeout - A function used for scheduling something to happen later

......以及其他许多人。它还会获取其中的所有其他内容,例如每个具有 id 的DOM元素的属性(属性的名称是 id ,它的值是对DOM元素的引用),在某些浏览器中,对于具有 name 属性的DOM元素也是如此,依此类推。它非常混乱。

...and many others. It also gets all kinds of other things thrown into it, such as a property for every DOM element that has an id (the property's name is the id, its value is a reference to the DOM element), on some browsers the same is true for DOM elements with a name property, and so on. It's very cluttered.

这篇关于变量称为“名称”总是在Javascript中定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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