Comments (3)
是不是贴错对应代码了?两段代码差别有点大……
from wind.
@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.
那编译器没错,你的content
变量只是在try
代码块里的局部变量。要在下一个content
里访问的话,可以把定义提出去。
from wind.
Related Issues (20)
- jquery tmpl 如何使用$await HOT 1
- arguments 在异步函数中无法使用的问题 HOT 1
- 与Commander的兼容性问题
- 为什么找不到文档了? HOT 3
- compileBlock
- 在windjs的基础上封装像golang一样的并行编程接口(内有代码) api like golang (code attach) HOT 1
- 如何为wind封装的函数,进行单元测试?
- windjs文档中的笔误
- 对于web端消除eval并保证效率的一点建议,以及相应写法的优化。
- What's the next step/future of windjs?
- http://windjs.org/ 官网网站打不开 HOT 3
- $await放在条件中,似乎编译出来的代码不正确
- Pit flaw in doc
- 这个项目停止了吗? HOT 3
- 编译函数时,对带特定带*的内容会编译失败~
- Can you add in the documentation how exactly is working? HOT 5
- 还在更新项目吗,想咨询下逆向问题,方便留着wx?
- 官方文档不维护了吗
- https://github.com/Fndroid/clash_for_windows_pkg/releases/download/0.20.5/Clash.for.Windows-0.20.5-mac.7z
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wind.