常见问题主题 - 如何使用字符串访问对象的属性? [英] FAQ Topic - How do I access a property of an object using a string?

查看:61
本文介绍了常见问题主题 - 如何使用字符串访问对象的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

----------------------------------------------- ------------------------

常见问题解答主题 - 如何使用字符串访问对象的属性?

-------------------------------------------- ---------------------------


有两种等效的访问属性的方法:点

表示法和方括号表示法。您正在寻找

for是方括号表示法,其中点和右侧的

标识符被替换为一组正方形

包含字符串的括号。字符串的值匹配

标识符。例如: -


//点符号

var bodyElement = document.body;


// square括号表示法,使用表达式

var bodyElement = document [" bo" +" dy"];

http://www.jibbering.com/faq/faq_not..._brackets.html

===

这样的发布每天自动发送一次。他们的b
目标是回答重复的问题,并将内容提供给社区进行持续评估/改进。完整的

comp.lang.javascript常见问题解答位于 http:/ /www.jibbering.com/faq/

FAQ工作人员是一群志愿者。

-----------------------------------------------------------------------
FAQ Topic - How do I access a property of an object using a string?
-----------------------------------------------------------------------

There are two equivalent ways to access properties: the dot
notation and the square bracket notation. What you are looking
for is the square bracket notation in which the dot, and the
identifier to its right, are replaced with a set of square
brackets containing a string. The value of the string matches
the identifier. For example:-

//dot notation
var bodyElement = document.body;

//square bracket notation, using an expression
var bodyElement = document["bo"+"dy"];

http://www.jibbering.com/faq/faq_not..._brackets.html
===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://www.jibbering.com/faq/.
The FAQ workers are a group of volunteers.

推荐答案

FAQ server写道:
FAQ server wrote:

------------------------ -----------------------------------------------

常见问题解答主题 - 如何使用字符串访问对象的属性?

--------------------- --------------------------------------------------


有两种方法可以访问属性:点

表示法和方括号表示法。
-----------------------------------------------------------------------
FAQ Topic - How do I access a property of an object using a string?
-----------------------------------------------------------------------

There are two equivalent ways to access properties: the dot
notation and the square bracket notation.



单词equivalent是多少?对吗?看起来像方括号

符号一般来说更强大。

Is the word "equivalent" correct here? It seems like square bracket
notation is more powerful in general.


Peter Michaux在11/17/2006上说了以下内容7:37 PM:
Peter Michaux said the following on 11/17/2006 7:37 PM:

FAQ server写道:
FAQ server wrote:

> ------- -------------------------------------------------- --------------
常见问题解答主题 - 如何使用字符串访问对象的属性?
------------ -------------------------------------------------- ---------

访问属性有两种等效方法:点
表示法和方括号表示法。
>-----------------------------------------------------------------------
FAQ Topic - How do I access a property of an object using a string?
-----------------------------------------------------------------------

There are two equivalent ways to access properties: the dot
notation and the square bracket notation.



单词等效是多少?对吗?


Is the word "equivalent" correct here?



不,它不正确。

No, it is not correct.


似乎方括号表示法一般更强大。
It seems like square bracket notation is more powerful in general.



但是,不是出于大多数人想的原因。
-

Randy

机会有利于准备好的思想

comp.lang.javascript常见问题 - http://jibbering.com/faq

Javascript最佳实践 - http://www.JavascriptToolbox.com/bestpractices/




Randy Webb写道:

Randy Webb wrote:

Peter Michaux在11/17/2006 7:37 PM发表以下内容:
Peter Michaux said the following on 11/17/2006 7:37 PM:

FAQ server写道:
FAQ server wrote:

--------------------------------- --------------------------------------

常见问题主题 - 如何使用字符串访问对象的属性?

------------------------------ -----------------------------------------


有两种等效的访问属性的方法:点

表示法和方括号表示法。
-----------------------------------------------------------------------
FAQ Topic - How do I access a property of an object using a string?
-----------------------------------------------------------------------

There are two equivalent ways to access properties: the dot
notation and the square bracket notation.


看起来方括号表示法通常更强大。
It seems like square bracket notation is more powerful in general.



但是,不是出于大多数人的想法。


It is, but, not for the reasons most people think.



大多数人的想法是什么?真正的原因是什么?

What do most people think? What are the real reasons?


这篇关于常见问题主题 - 如何使用字符串访问对象的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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