javascript中称为“名称"的全局变量是什么? [英] What is the global variable called 'name' in javascript?

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

问题描述

为什么将DOM元素分配给全局变量"name"不起作用?

Why is it that assigning a DOM element to the global variable "name" doesn't work ?

推荐答案

在浏览器中运行时,JavaScript中的大多数全局变量"实际上是window对象的属性(类型为

Most "globals" in JavaScript when running in a browser are actually properties of the window object (of type Window).

但是Window已经有一个 name 属性,因此任何尝试为其分配非字符串的尝试都将导致转换为字符串:所分配对象的类型将不会保留.

But Window already has a name property, so any attempt to assign a non-string to it is going to lead to conversion to a string: the type of the assigned object will not be maintained.

这篇关于javascript中称为“名称"的全局变量是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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