好吧,我知道标题是相当复杂的,但问题很难在一行中..太对不起。什么是最好的做法,以获得具有相同的项目从另一个阵列的项目
目的:我想在所有模块都可用时运行回调 问题:什么是最快的方法? 例子:
在功能问题开始“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:是的,这些是模块 –