我现在改用 es6 写 angularjs 了,装上 chrome55,可以不用 babel 就把代码跑起来。待发布的时候再 babel 编译并且打包一下。
用 es6 写脚本有几个地方很好用:
1. 使用 class 定义类型。比如 ngview 的页面我弄了一个 BasePage 类型,这么写很方便:
class ConfigurePage extends BasePage {
constructor(scope) {
super(scope);
this.scope['configure'] = {};
this.scope['save'] = this.save.bind(this);
}
async run() {
var http = this.getTransport();
var response = await http({
"url": "/api/v1/configure/",
});
this.scope['configure'] = response.data;
this.emitDataChanged();
}
async save() {
var http = this.getTransport();
await http({
"url": "/api/v1/configure/",
"data": this.scope["configure"],
"method": "POST",
});
}
}
很多东西都可以写在父类里面公用。
2. 可以用 await,比写回调舒服很多。
3. 指令同样也可以继承于 BaseDirective
--
修改:hgoldfish FROM 211.162.33.*
FROM 120.36.226.*