所以,我有一个友好的邻居对象构造函数,就像这样;
function Clip(a, b)
{
this.track = a
this.slot = b
this.path = "live_set tracks " + a + " clip_slots " + b + " clip "
clip = new LiveAPI(this.patcher, this.path)
this.length = clip.get("length")
}
我想做的是
- 将任意数量的它们添加到数组中
- 当数组的长度达到 8 时,将该数组添加到新的“ super ”数组并开始一个新数组。
换句话说,超数组应该允许我访问对象的属性和方法,例如,clip[0][0].length - Clip[0][7].length
、clip[1][0].length - Clip[1][7].length
等
最佳答案
这是您要找的吗?我简化了一些代码,但总体思路似乎是合适的。
http://jsfiddle.net/bryandowning/pH6bU/
var superArr = [];
function Clip(a) {
this.length = a;
}
/*
* num: number of clip collections to add to container
* max: number of clips per collection
* container: array to add collections to
*/
function addClips( num, max, container ){
while(num--){
// arr: a collection of clips
var arr = [];
for( var i = 0; i < max; i++ ){
arr.push(
// just did a random number for the length
new Clip( Math.floor( Math.random() * 10 ) )
);
}
container.push( arr );
}
}
addClips( 5, 8, superArr );
console.log( superArr );
console.log( superArr[0][0].length );
关于javascript - 如何在 Javascript 中创建自定义对象数组的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11277890/