且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么样的数据类型?

更新时间:1970-01-01 07:59:06

>>大家好:
>>Hi everybody:
我是Javascript的新手,我发现了一些代码,并且有:
var fruit =
{
''apple'':{''重量'':10,''成本'':9},
''桃'':{''重量'':19,''成本'':10}
} >有人可以告诉我什么样的数据类型是水果??
I''m new in Javascript, I found some code and there is this: var fruit =
{
''apple'' : { ''weight'' : 10, ''cost'' : 9},
''peach'' : { ''weight'' : 19, ''cost'' : 10}
}
somebody can tell me what kind of data type is fruit??




你好gt,


水果是Object类型。更具体地说,这是一个对象文字。

它只是创建和初始化新对象的另一种方式。


你看到的代码就是创建一个具有属性的新对象

''apple''和''peach''。反过来,''apple''和''桃子,也有属性

''重量''和''成本''。


希望这个澄清。



Hi gtux,

fruit is of type Object. More specifically, this is an object literal.
It''s just another way of creating and initialize new objects.

The code that you see is creating a new Object with the properties
''apple'', and ''peach''. In turn, ''apple'' and ''peach, also have properties
''weight'' and ''cost''.

Hope this clarifies.


gtux写道:
gtux wrote:
var fruit =
{
'' apple'':{''weight'':10,''cost'':9},
''peach'':{''weight'':19,''cost'':10}
}

有人可以告诉我什么样的数据类型是水果??
var fruit =
{
''apple'' : { ''weight'' : 10, ''cost'' : 9},
''peach'' : { ''weight'' : 19, ''cost'' : 10}
}

somebody can tell me what kind of data type is fruit??




''fruit''是一个对象两个属性''apple''和''peach'',他们自己

每个具有两个属性的对象(''weight''和''cost'')。


此构造{/*...*/}被称为对象文字(或对象

初始化),即一个表达式,它创建一个对象并同时初始化

。它相当于:


var fruit = new Object(); //或var fruit = {};

fruit.apple = {''weight'':10,''cost'':9};

fruit.peach = {''weight'':19,''cost'':10};





var fruit = new Object( ); //或var fruit = {};

fruit.apple = new Object(); //或fruit.apple = {};

fruit.apple.weight = 10;

fruit.apple.cost = 9;

//等。


您可以在ECMAScript中了解有关对象文字的更多信息

规范,§11.1.5。

HTH,

是的。



''fruit'' is an object with two properties ''apple'' and ''peach'', themselves
objects with two properties each (''weight'' and ''cost'').

This construct "{/*...*/}" is called object literal (or object
initialiser), i.e an expression which creates an object and initialises
it at the same time. It is equivalent to:

var fruit=new Object(); // or var fruit={};
fruit.apple= { ''weight'' : 10, ''cost'' : 9};
fruit.peach= { ''weight'' : 19, ''cost'' : 10};

or

var fruit=new Object(); // or var fruit={};
fruit.apple=new Object(); // or fruit.apple={};
fruit.apple.weight=10;
fruit.apple.cost=9;
//etc.

You can read more about the object literal in the ECMAScript
specification, §11.1.5.
HTH,
Yep.






gtux wrote:
各位大家好:

我是Javascript的新手,我找到了一些代码就有了这个:

var fruit =
{
''peach'':{''weight'':19,''cost'' :10}
}
有人可以告诉我什么样的数据类型是水果??
Hi everybody:

I''m new in Javascript, I found some code and there is this:

var fruit =
{
''apple'' : { ''weight'' : 10, ''cost'' : 9},
''peach'' : { ''weight'' : 19, ''cost'' : 10}
}

somebody can tell me what kind of data type is fruit??




嵌套哈希表,又名地图表也称为联想数组(选择你喜欢的
)。



Nested Hash table, aka Map table aka Associative array (choose what you
like).