在MDC发现这个但如何如果我想一个私有变量添加到如何将私有变量添加到此Javascript对象文字片段?
var dataset = {
tables:{
customers:{
cols:[ /*here*/ ],
rows:[ /*here*/ ]
},
orders:{
cols:[ /*here*/ ],
rows:[ /*here*/ ]
}
},
relations:{
0:{
parent:'customers',
child:'orders',
keyparent:'custid',
keychild:'orderid',
onetomany:true
}
}
}
我明白OOP在JavaScript的方式,我想有机会获得dataset.tables.customers.cols [0 ]如果这样的项目存在。
但是,如果我想将一个私有变量放入客户,那会是什么样子?
添加var index = 0;
会导致运行时错误。
哦!我想你让我回到正轨。数据结构不能拥有私有成员,因为他们只是声明数据(一切都是公开的!),但如果我将它重写成静态类/ singlelton(var obj = function(){}();),我将能够如此。那是对的吗?谢谢。 :) – 2009-09-08 21:19:52