【发布时间】:2017-07-15 06:39:48
【问题描述】:
我正在用 Javascript 创建一个 UWP 应用。我需要将一些代码从 C# 翻译成 javascript。
我正在关注Documentation,了解如何添加应用内购买。
C#中的需求代码如下:
async void BuyFeature()
{
if (!licenseInformation.ProductLicenses["featureName"].IsActive)
{
try
{
// The customer doesn't own this feature, so
// show the purchase dialog.
await CurrentAppSimulator.RequestProductPurchaseAsync("featureName", false);
//Check the license state to determine if the in-app purchase was successful.
}
catch (Exception)
{
// The in-app purchase was not completed because
// an error occurred.
}
}
else
{
// The customer already owns this feature.
}
}
正如你在第 9 行看到的,有一个等待函数。我如何将其翻译成 javascript?
所以在调用 javascript 之后...
function abc() {
Windows.ApplicationModel.Store.CurrentAppSimulator.requestProductPurchaseAsync("1", false);
// something fancy here ... but that needs to wait
};
...我需要等到它返回一些东西,然后继续执行该函数。
【问题讨论】:
-
@GeomanYabes 我已经看过这个(也是 async function 上的 MDN 文档),但是使用它们会出现错误。
标签: javascript uwp async-await