最近自己试验性的写了一个可以实现同步调用的JS函数。
使用的递归的原理。
var syncExe = function(){
var fLen = arguments.length;
var exe = function(funcs,count,sum,retval){
if(!!retval){
if(!('return' in exe)){
exe['return'] = [];
}
exe['return'].push(retval);
}
if(count == sum){
return;
}else{
funcs[count](function(str){
count++;
exe(funcs,count,sum,str);
});
}
}
exe(arguments,0,fLen);
return exe['return'];
};

![19639_o[1]](https://www.z-en.com/wp-content/uploads/2012/03/19639_o1-1024x764.jpg)

![10619_o[1]](https://www.z-en.com/wp-content/uploads/2011/10/10619_o1.png)
![10620_o[1]](https://www.z-en.com/wp-content/uploads/2011/10/10620_o1.png)
![10622_o[1]](https://www.z-en.com/wp-content/uploads/2011/10/10622_o1.png)
![10623_o[1]](https://www.z-en.com/wp-content/uploads/2011/10/10623_o1.png)