JeffreyZhao / wind

Asynchronous flow control in JavaScript, with JavaScript.
http://windjs.org/
1.54k stars 238 forks source link

arguments 在异步函数中无法使用的问题 #73

Open hthubert opened 12 years ago

hthubert commented 12 years ago

由于代码编译后,运行上下文发生变化 arguments 对象语义也发生变化,所以用 arguments 判断参数的方法已无法使用了,这个不是大问题也很容易解决,可还是会引起一些麻烦,希望能给一个编程规范来避免这样的问题

源代码

eval(Wind.compile("async", function(/*[String], Date*/){
        var seg, date;
        switch (arguments.length){
            case 0:
                date = Date.now();
                break;
            case 1:
                date = arguments[0];
                break;
        }
});

编译后的代码

/* async << function () { */                     (function () {
                                                     var _builder_$0 = Wind.builders["async"];
                                                     return _builder_$0.Start(this,
                                                         _builder_$0.Delay(function () {
/*     var seg, date; */                                     var seg, date;
/*     switch (arguments.length) { */                        switch (arguments.length) {
/*         case 0: */                                            case 0:
/*             date = Date.now(); */                                 date = Date.now();
/*             break; */                                             break;
/*         case 1: */                                            case 1:
/*             date = arguments[0]; */                               date = arguments[0];
/*             break; */                                             break;
/*     } */                                                  }
                                                         })
                                                     );
/* } */                                          })
JeffreyZhao commented 12 years ago

还真是这样,多谢。