Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

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

Open
hthubert opened this Issue · 1 comment

2 participants

@hthubert

由于代码编译后,运行上下文发生变化 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
Owner

还真是这样,多谢。

@JeffreyZhao JeffreyZhao was assigned
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.