我看到了下面的代码,想知道除了强制该方法具有关键字之外async,在最后一条指令上指定等待是否有用?例子
async example(){
//... whatever code
//Last instruction
await functionReturningAPromise()
}
Run Code Online (Sandbox Code Playgroud)
请注意,在这里我怀疑退货丢失了,但即使有退货,我的问题仍然存在。
async example(){
//... whatever code
//Last instruction
return await functionReturningAPromise() //Is this useful ? or should we return directly
}
Run Code Online (Sandbox Code Playgroud)
我个人认为没有真正的兴趣。
在地方变更上更新活动状态的最佳做法是什么?想象一下,您有一个带有视图的活动,该活动显示类别列表和类别中的项目列表.如果选择了不同的类别,则应用程序将转到具有类别ID的新位置.我想要只刷新项目,而不是创建也重新读取类别列表的新活动.
我目前的做法是这样的:
public class AppActivityMapper implements ActivityMapper {
private ItemListActivity itemListActivity;
...
public Activity getActivity(final Place place) {
final Activity activity;
if (place instanceof ItemListPlace) {
if (itemListActivity == null) {
itemListActivity = new ItemListActivity((ItemListPlace) place, clientFactory);
} else {
itemListActivity.refresh((ItemListPlace) place);
}
activity = itemListActivity;
} else {
itemListActivity = null;
}
...
return activity;
}
...
Run Code Online (Sandbox Code Playgroud) 如果您对 getter/setter 使用以下 es6 语法
class Person {
constructor(name) {
this._name = name;
}
get name() {
return this._name.toUpperCase();
}
set name(newName) {
this._name = newName;
}
}
Run Code Online (Sandbox Code Playgroud)
您将如何存根 getter 方法?
const john = new Person('john')
sinon.createSandbox().stub(john, 'name').returns('whatever')
Run Code Online (Sandbox Code Playgroud)
似乎不起作用。
ecmascript-6 ×2
javascript ×2
async-await ×1
function ×1
gwt ×1
gwt-mvp ×1
gwt-places ×1
mvp ×1
promise ×1
sinon ×1