![](/img/trans.png)
[英]JavaScript: how can I merge these two arrays of incomplete objects and make an array of complete objects
[英]How can I make an array of arrays of custom objects in Javascript?
因此,我有一個友好的鄰域對象構造函數,就像這樣;
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")
}
我想做的是
換句話說,超級數組應該允許我通過例如clip[0][0].length - clip[0][7].length
, clip[1][0].length - clip[1][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 );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.