好吧,我知道標題是相當複雜的,但問題很難在一行中..太對不起。什麼是最好的做法,以獲得具有相同的項目從另一個陣列的項目
目的:我想在所有模塊都可用時運行回調 問題:什麼是最快的方法? 例子:
在功能問題開始「runCallbacks」是獲取所有新添加的對象是這樣的:
runCallbacks(newItems/*as array ['a','b','c'];*/){
// now I would need to understand the dependencies of the callbacks
// each callback might depend on one or more objects
// iNeed(['a','b'], toRunThis);
// | |-callback to run when those are ready
// |-are the dependencies
我在想什麼的是這樣的:
callbacks = [[[callbackFunction],['loadedItems'],['notLoadedItems']]]
|-----------it's a single callback--------------------|
具有良好性能還是你有更好的主意? 感謝
又如
this.use(['a', 'b'], function(){/* do something with 'a' and 'b' only when are ready */})
use: function(paths, callback, target/*not used in this case*/){
// "a", "b", 'c' module is available
// "d", 'e' module is not available
this.callbacks.push([[target], ['a', 'b', 'c'], ['d', 'e']]);
// | |-not loaded
// |-loaded
}
// then an object might be added
this.add({...})
// then will check if this new object may make some callbacks to run
function(newPaths/* ['d'] */){
// loop all callbacks items
// remove items from [not loaded array] and put to [loaded array] if
// exists in newPaths
// in this case the callback already has: a,b,c; but misses: d,e;
// now it will add "d" to the loaded array
// and now only miss the "e" path
所以如果回調需要「A」和「B」,但不存在節省了當兩個準備回調 我添加了「A」和「B」模塊然後我想知道女巫的回調已經準備就緒;
回調可能有多個依賴性 「一」模塊可能由多個回調 這就是爲什麼是有點複雜
您談論的模塊是'a','b'和'c'元素嗎? – Jad
你需要經常相交嗎?或者是什麼問題?你需要澄清。 – jishi
@Jad:是的,這些是模塊 –