Giter Club home page Giter Club logo

Comments (3)

JeffreyZhao avatar JeffreyZhao commented on July 26, 2024

是不是贴错对应代码了?两段代码差别有点大……

from wind.

kmod-midori avatar kmod-midori commented on July 26, 2024

@JeffreyZhao 不好意思确实贴错了。。
我有一个有相同问题的代码:

/*     var exist = $await(fs.existsAsync(path)); */      return _builder_$0.Bind(fs.existsAsync(path), function (exist) {
/*     if (exist) { */                                       if (exist) {
                                                                 return _builder_$0.Combine(
/*         try { */                                                  _builder_$0.Try(
                                                                         _builder_$0.Delay(function () {
/*             var content = $await(fs.readFileAsync(path)); */              return _builder_$0.Bind(fs.readFileAsync(path), function (content) {
                                                                                 return _builder_$0.Normal();
                                                                             });
                                                                         }),
/*         } catch (err) { */                                            function (err) {
/*             err.message = "Cannot read config file:" + err.message; */    err.message = "Cannot read config file:" + err.message;
/*             throw err; */                                                 return _builder_$0.Throw(err);
/*         } */                                                          },
                                                                         null
                                                                     ),
                                                                     _builder_$0.Delay(function () {
/*         try { */                                                      try {
/*             var conf = JSON.parse(content); */                            var conf = JSON.parse(content);
/*         } catch (err) { */                                            } catch (err) {
/*             err.message = "Invalid config data:" + err.message; */        err.message = "Invalid config data:" + err.message;
/*             throw err; */                                                 return _builder_$0.Throw(err);
/*         } */                                                          }
/*         this.data = conf; */                                          this.data = conf;
/*         this.path = path; */                                          this.path = path;
/*         return true; */                                               return _builder_$0.Return(true);
                                                                     })

在第二个try..catch...那里没有办法读取到content的值。
目前我的做法是把content放到全局作用域里面,在结束操作时删除

from wind.

JeffreyZhao avatar JeffreyZhao commented on July 26, 2024

那编译器没错,你的content变量只是在try代码块里的局部变量。要在下一个content里访问的话,可以把定义提出去。

from wind.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.