English 中文(简体)
Java字本中使用的财产名称变量?
原标题:Use variable for property name in JavaScript literal?
  • 时间:2011-10-03 17:45:18
  •  标签:
  • javascript

我知道,我们能够在 run印物体的运行期间创造新的财产,但财产也可以被分配价值? 例如。

var value = "New value";

var table = new Object();

var newValue = table[value];

现在我知道,价值表有一种新的财产,称为“价值”。 但是,“价值的关键含有“新价值”的信息。 因此,现在就这样说:

table = {
value:"New Value";
}
最佳回答

你们在分配时会混淆。

// Assigns a variable named  value  with a value of  New Value .
var value = "New value";
// Creates a variable named  table  as a blank Object.
var table = new Object(); // Alternatively - table = {};
// Attempts to access "New Value" from object "table" which returns undefined.
var newValue = table[value];

如果你想把财产分配给某个物体,那么你就是这样:

// Assumes table is still an object.
table[ key ] =  value ;

// Note that I almost _always_ opt for the variable[ key ] notation over
// the variable.key notation because it allows you to use keys
// that would otherwise not be valid as identifiers.
table[ Some Key ] =  Some Value ; // This works.
table.Some Key =  Some Value ; // This does not.

后来,当你想收回这一价值并把它储存在一个新的变数中时,你会这样做:

var newVariable = table[ key ];

希望能澄清一些。 请允许我知道,我是否可以扩大这一部分。

问题回答

页: 1

http://www.ohchr.org。

is not setting anything, and since at the time when you created table you didn t assign any property, newValue will be undefined.

如果您有一份分配价值的<条码>值/代码>变量,并且希望将这一数值分配到关键<条码>值/代码下。

<>代码>[价值] = 价值;

或替代

<代码>表>价值 = 数值

埃尔姆,第一点,我不认为你这样做是正确的。

所有这些都转让了<代码>un specified至newValue ,因为你试图查阅table s“ New Value”,而这种财产确实存在。

What I think you re trying to do is this:

var value = "New value";
var table = {};
table.value = value;




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签