mirror of
https://shylinux.com/x/volcanos
synced 2025-04-25 16:58:06 +08:00
32 lines
1.3 KiB
JavaScript
32 lines
1.3 KiB
JavaScript
Volcanos("core", {help: "核心模块",
|
|
Item: shy("迭代器", function(obj, cb) {var list = [];
|
|
for (var k in obj) {var res;
|
|
list.push(typeof cb == "function" && (res = cb(k, obj[k])) != undefined && res || k)
|
|
}
|
|
return list
|
|
}),
|
|
List: shy("迭代器", function(obj, cb, interval, cbs) {obj = typeof obj == "string"? [obj]: (obj || [])
|
|
if (interval > 0) {
|
|
function loop(i) {if (i >= obj.length) {return typeof cbs == "function" && cbs(obj)}
|
|
typeof cb == "function" && cb(obj[i], i, obj), setTimeout(function() {loop(i+1)}, interval);
|
|
}
|
|
obj.length > 0 && setTimeout(function() {loop(0)}, interval/4);
|
|
return obj;
|
|
}
|
|
|
|
var list = [], res;
|
|
for (var i = 0; i < obj.length; i++) {
|
|
typeof cb == "function"? (res = cb(obj[i], i, obj)) != undefined && list.push(res): list.push(obj[i]);
|
|
}
|
|
return list;
|
|
}),
|
|
Next: shy("迭代器", function(obj, cb, cbs) {obj = typeof obj == "string"? [obj]: (obj || [])
|
|
function next(list, cb) {
|
|
list && list.length > 0? typeof cb == "function" && cb(list[0], function() {
|
|
list.length > 0 && next(list.slice(1), cb)
|
|
}): typeof cbs == "function" && cbs()
|
|
}
|
|
next(obj, cb)
|
|
}),
|
|
})
|