找不到变量:Safari 上的承诺 [英] Can't find variable: Promise on Safari
问题描述
我正在开发一个网站,它可以在桌面版 Chrome 上完美运行(Windows 8.1 & OS X Mavericks)
I have a site I'm working on that runs perfectly on Chrome for the desktop (Windows 8.1 & OS X Mavericks)
当我在 iOS 7 或 Safari 7.0.2 上运行它时,我收到一个错误消息到控制台,指出
When I run it on iOS 7 or Safari 7.0.2 I get an error to the console that states
加载路由时出错:checkIfLoggedIn
Error while loading route: checkIfLoggedIn
它在消息中指定的成员不是路由,而是返回承诺的方法.当我通过 ember 代码调试以找出出了什么问题时,我发现它拒绝了承诺,原因是
the member it specifies at the message is not a route, it is a method that returns a promise. When I debug through the ember code to figure out what is going wrong I found that it is rejecting the promise with the reason of
找不到变量:Promise
Can't find variable: Promise
我无法在此处发布我网站上的实际代码,因此我着手创建一个重现错误的小提琴,并且我能够想出这个:
I can't post the actual code from my site here, so I set out to create a fiddle that reproduces the error and I was able to come up with this:
http://jsfiddle.net/NQKvy/851/
这在桌面版 Chrome(Windows 8.1 和 OS X Mavericks)上完美运行,但在 iOS 7 或 Safari 7.0.2 上向控制台抛出以下错误
This runs perfectly on Chrome for the desktop (Windows 8.1 & OS X Mavericks), but on iOS 7 or Safari 7.0.2 throws the following error to the console
ReferenceError:找不到变量:Promise
ReferenceError: Can't find variable: Promise
有人知道为什么这不起作用吗?
Anyone have any ideas why this isn't working?
总结:
- 我已经在适用于 Windows 8.1 和 OS X Mavericks 的 Chrome 上进行了测试 - 有效
- 我已经在 Chrome for iOS 上进行了测试,但它不起作用
- 我已经在 Safari for iOS 和 OS X Mavericks 上进行了测试,但它不起作用
- 我根本没有在 Android 上进行过测试(我目前无法访问任何设备)
这让我相信这是一个 Safari 错误,因为(如果我没记错的话)iOS 版 Chrome 使用 Safari 控件而不是 Chromium 来呈现页面
This leads me to believe that it is a Safari error as (if I recall correctly) Chrome for iOS uses a Safari control to render the page rather than Chromium
这是我用来生成错误的代码:
This is the code I'm using to generate the error:
App.ready = function() {
var asdf = new Promise(function (resolve) {
var i = 1;
i++;
resolve.call(this,i);
}).then(function (result) {
alert('I: ' + result);
});
};
推荐答案
原来在 Safari 上创建 promise 时必须使用全限定名,否则将不起作用:
Turns out that on Safari you must use the fully qualified name when creating a promise, otherwise it will not work:
App.ready = function() {
var asdf = new Ember.RSVP.Promise(function (resolve) {
var i = 1;
i++;
resolve.call(this,i);
}).then(function (result) {
alert('I: ' + result);
});
};
注意new Ember.RSVP.Promise"而不是new Promise".这似乎为我解决了这个问题.
Note the 'new Ember.RSVP.Promise' instead of the 'new Promise'. This appears to fix it for me.
这篇关于找不到变量:Safari 上的承诺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!