简体   繁体   English

javascript中的window [“ name”]和window.name

[英]window[“name”] and window.name in javascript

I'm a beginner of javascript. 我是javascript的初学者。 Here is my question. 这是我的问题。

Is there any difference between window["property_name"] and window.property_name in javascript? javascript中的window [“ property_name”]和window.property_name有什么区别?

These forms are identical when name is a valid JavaScript identifier ; name是有效的JavaScript 标识符时,这些形式是相同的 in this case the property name is "name" . 在这种情况下,属性名称为"name"

The form with braces is required when the property name is an arbitrary expression ( obj[propNameVariable] ) or the property name is not a valid identifier ( obj["invalid identifier"] ). 当属性名称是任意表达式( obj[propNameVariable] )或属性名称不是有效的标识符( obj["invalid identifier"] )时,必须使用大括号形式。

All property names in JavaScript are internally strings. JavaScript中的所有属性名称在内部都是字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM